I'm using a Table View.
I'd like to remove the cell padding (or margin) so I can squeeze more cells in less space. How can this be achieved?
The cells size is set to 32 pixels on QT designer, if I set it smaller, the cells contents don't show and an ellipsis appears. (...)
alt text http://img692.imageshack.us/img692/3484/tableviewpng.png
Recommend you to use this code:
QTableView *tableView = new QTableView(this);
tableView->setModel(model_);
QHeaderView *verticalHeader = tableView->verticalHeader();
verticalHeader->setDefaultSectionSize(verticalHeader->fontMetrics().height()+2);
// or ...
QHeaderView *horizontalHeader = tableView->horizontalHeader();
horizontalHeader->setStretchLastSection(false);
horizontalHeader->resizeSection(/* your personal height */);
PS: Also I have noticed, that if in tableView too much rows or columns, for example about 20K rows or more, this functions resizeSection() may be too slow...
Related
I am trying to set the minimum height of the rows in the QComboBox dropdown menu without changing their width or the size of the QComboBox itself.
By default the width and height of the row items are calculated by its data. To make the dropdown list resize to the width of the data I am calling
view()->setMinimumWidth(view()->sizeHintForColumn(0);
in the combobox's ::showPopup().
However, since I have different font sizes in rows, I would like to enforce a minimum height on each row.
I tried to use setSizeHint on each QStandardItem that is added in the first column to the rows but without success. I tried:
item->setSizeHint(QSize(item->sizeHint().width(), minHeight));
(https://stackoverflow.com/a/10749345/1981832)
But this lead to the dropdown menu not resizing to the data's width.
So, I tried to leave the width "unset". However, both
item->setSizeHint(QSize(QSize().width(), minHeight));
and
item->setSizeHint(QSize(0, minHeight));
did not work. Does anyone have an idea how I can enforce a minimum height on the rows of the QComboBox without messing up the automatic width calculation?
Just use this lines:
QComboBox combo;
QListView *view = new QListView(&combo);
view->setStyleSheet("QListView::item{height: 100px}");
combo.setView(view);
Or write this code in qss file:
QListView::item {
height: 30px;
}
After that use:
QComboBox::setView(QAbstractItemView *itemView)
I have a QDialog window like this and I want to delete the space between 'Length', 'n', 'm' and corresponding QLineEdit input boxes. How can I achieve that ?
If you use gridlayout, I am not sure why your output looks like that. Generally Qt will not leave huge empty space like that, There are three possibility I can think of:
You have many SPACE after Length:, M: or N:
The layoutHorizontalSpacing is too large in your grid manager.
The layoutColumnStretch was set to in favor of label in your grid manager, should be "0,0", not "1,0". I mean, stretch of Label should not be higher than lineedit.
Still, I would use a simple form layout in your application.
All you need to do is reset the alignment of the labels:
label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlighVCenter)
This can also be done in via the Property Editor in Qt Designer.
You have to decide what to do with the space you want to remove :
Reduce the whole widget : it depends on the surrounding layout, adding an horizontal layout on right or left of it will put the space out of your widget.
Space on the left of your labels : you can align the label text to the right as ekhumoro suggested, or directly reduce and align to the right the whole frame by adding an horizontal spacer on its left (in the surrounding layout).
Space on the right of your line-edits : like above you can add horizontal spacers or reduce and align the frame.
Expand the line-edits : remove their fixed width (default horizontal policy is expanding) or set a bigger one.
The point is : the space has to be somewhere except if you reduce the parent widget or enlarge some the inner widgets. Size-policy is useful to tell which widget should take the available space, spacers are useful to let empty space between widgets.
I have several qdockwidget and within these a qtableview, as seen in the attached picture, my problem is I want the tables are the same size of the dock.
I tried to do this and it does not work:
table-> resize (dock-> size());
By default, the cells in a table do not expand to fill the available
space. You can make the cells fill the available space by stretching
the last header section. Access the relevant header using
horizontalHeader() or verticalHeader() and set the header's
stretchLastSection property.
Source: QTableView Documentation
I hope that helps you. Cheers.
I want to implement paging in a spark text area. For that I want to find out the number of lines a spark textArea can hold before the scrollbars appear and just feed that much lines to the text area.
http://blog.flexexamples.com/2010/01/13/determining-the-number-of-lines-in-a-spark-richeditabletext-control-in-flex-4/
The number of lines a TextArea can hold before a vertical ScrollBar appear is determinated by the heightInLines property.
The code
var number_of_lines:int=textArea.heightInLines;
will return inside the variable number_of_lines the number of lines you are looking for, and textArea is the id of the TextArea object you are checking.
var numLines:int=t.heightInLines;
var numChars:int=t.widthInChars;
The documentation:
spark.components.TextArea.heightInLines():Number The default height of
the control, measured in lines. The control's formatting styles, such
as fontSize and lineHeight, are used to calculate the line height in
pixels.
You would, for example, set this property to 5 if you want the height
of the RichEditableText to be sufficient to display five lines of
text.
If this property is NaN (the default), then the component's default
height will be determined from the text to be displayed.
This property will be ignored if you specify an explicit height, a
percent height, or both top and bottom constraints.
RichEditableText's measure() method uses widthInChars and
heightInLines to determine the measuredWidth and measuredHeight. These
are similar to the cols and rows of an HTML TextArea.
Since both widthInChars and heightInLines default to NaN,
RichTextEditable "autosizes" by default: it starts out very small if
it has no text, grows in width as you type, and grows in height when
you press Enter to start a new line.
I have a widget which I'm putting in a QVBoxLayout. This widget's layout is a QVBoxLayout which includes a QTableWidget. When I display this everything is fine but the QTableWidget only shows a few rows. How can I set the height of the table to a decent value (like 20 rows) while still allowing the table to resize?
I've tried calling table.setMinimumHeight(200) but then the table can NEVER be smaller than 200. I've also tried setting the container widget height using setMinimumHeight but this has the same problem.
Check the sizePolicy for the QTableWidget. This will have horizontal and vertical size policies which, if I understand you correctly, should be set to "expanding" or "minimum expanding". There are a number of options and combinations for these and sometimes it can be tricky getting the right combination for all the widgets in your layout to get what you are looking for.
The size policies will work in combination with your min/max height/width settings and those of the other widgets in the layout.