QTreeWidget: how to limit the number of displayed rows?
With the Designer, I have placed two QTreeWidget on a QVBoxLayout. I would like to force the upper one to display only 4 rows, giving more space to the lower one. I can obtain something of acceptable by limiting the maximum size with the designer, but I would like to be independent on the pixel and limits in term of rows, in particular to the number of used rows.
How can I do?
As far as I know there is no easy way to achieve this. One has to account for the frame size of the scroll area, individual row heights (including font size, multi-line rows), header height, scroll bars and probably more in a platform independent way.
you should use QTreeView, and implement your custom model. So you can choose the number of "rowCount" for each parent node in the tree.
I suppose you could also insert a QSortFilterProxyModel-derived class and reimplement filterAcceptRows in order to reject all rows which have index.row() > 4.
in designer on a upper QTreeWidget, Make minimumSize and maximumSize Height a same number as geometry height.
Add four rows and do a quick preview (ctrl + r). Come back and re-adjust that number based on how it previews. Once you are satisfied, you've your perfect locked-down state. If you resize the widget, this treewidget wouldn't resize.
Alternately, you could set the vertical sizepolicy as fixed.
iunknwn: it is not a good solution. Rows can have different heights, in other OSes there can be another sizes in styles and so on.
The proxy filter model solutions seems not to be what the user wants. The tree widget should have a height to show 4 rows simultaneously and provide a scroll bar if there are more than 4 rows to display.
Another solution might be to use a "QSplitter":http://doc.qt.nokia.com/4.7/qsplitter.html, let the user choose the ratio between the two widgets and save the splitter's state when closing the window or quitting the application.