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. Dynamically show/hide QTreeView items.
Qt 6.11 is out! See what's new in the release blog

Dynamically show/hide QTreeView items.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.4k 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.
  • S Offline
    S Offline
    spsingh
    wrote on last edited by
    #1

    I have an application setting based on which I need to show/hide items in my QTreeView, but my model should remain same. I tried returning empty QVariant() in the decorationRole and displayRole and returning QSize(0,0) in sizeHintRole. But the invisible items do not resize to zero height. How do I achieve this?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      ludde
      wrote on last edited by
      #2

      Have you had a look at QSortFilterProxyModel?
      It's a very convenient way of filtering out parts of your model.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        For such things, you typically 8use a QSortFilterProxyModel in between. Have a look at "models and views":http://doc.qt.nokia.com/4.7/model-view-programming.html#proxy-models

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          spsingh
          wrote on last edited by
          #4

          Thanks a lot guys, I should have read the docs more carefully.

          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