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?
6 replies
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.
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 [doc.qt.nokia.com], let the user choose the ratio between the two widgets and save the splitter’s state when closing the window or quitting the application.
See
QSplitter::saveState() [doc.qt.nokia.com]
QSplitter::restoreState() [doc.qt.nokia.com]
QSettings [doc.qt.nokia.com]
for details.
You must log in to post a reply. Not a member yet? Register here!





