Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeWidget: how to limit the number of displayed rows?
Forum Updated to NodeBB v4.3 + New Features

QTreeWidget: how to limit the number of displayed rows?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 6 Posters 8.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    calberto
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tony
        wrote on last edited by
        #3

        Hi,

        you should use QTreeView, and implement your custom model. So you can choose the number of "rowCount" for each parent node in the tree.

        T.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dfaure
          wrote on last edited by
          #4

          I suppose you could also insert a QSortFilterProxyModel-derived class and reimplement filterAcceptRows in order to reject all rows which have index.row() > 4.

          David Faure (david.faure@kdab.com)
          KDE/Qt Senior Software Engineer
          KDAB - Qt Experts - Platform-independent software solutions

          1 Reply Last reply
          0
          • I Offline
            I Offline
            iunknwn
            wrote on last edited by
            #5

            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.

            Vista x64 with Qt 4.8.2 and VS2010

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                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.

                See
                "QSplitter::saveState()":http://doc.qt.nokia.com/4.7/qsplitter.html#saveState
                "QSplitter::restoreState()":http://doc.qt.nokia.com/4.7/qsplitter.html#restoreState
                "QSettings":http://doc.qt.nokia.com/4.7/qsettings.html
                for details.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved