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. QTreeView: Too many columns. What to do?

QTreeView: Too many columns. What to do?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 523 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.
  • I Offline
    I Offline
    IDontKnowHowToCode
    wrote on last edited by
    #1

    My tree view has too many columns, so the user would have to scroll sideways to view them all. My idea is to group columns together, so the user can hide groups and show them again. Has anyone ever tried this? I'm not sure how to visualize the groups and add a button (or similar) to collapse them. Does anyone know an easy way to do this?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Proxy models are what you need.

      QSortFilterProxyModel should suit your needs to filter (or sort if ever needed) your columns.

      However this won't be enough for grouping, I think you will have to inherit QAbstractProxyModel.

      If you want to have a button or so that would allow for hide/show columns, you simply connect the button to the appropriate slot in the proxy model.

      JonBJ 1 Reply Last reply
      0
      • ? A Former User

        Proxy models are what you need.

        QSortFilterProxyModel should suit your needs to filter (or sort if ever needed) your columns.

        However this won't be enough for grouping, I think you will have to inherit QAbstractProxyModel.

        If you want to have a button or so that would allow for hide/show columns, you simply connect the button to the appropriate slot in the proxy model.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @ankou29666 said in QTreeView: Too many columns. What to do?:

        QSortFilterProxyModel should suit your needs to filter (or sort if ever needed) your columns.

        The OP appears (to me?) to want to hide columns. How would QSortFilterProxyModel ever hide a complete column (as opposed to showing the column with blank values in it)?

        I agree about proxy model which removes undesired columns, but I don't see QSortFilterProxyModel doing that (it can remove rows but not columns)?

        ? Christian EhrlicherC 2 Replies Last reply
        0
        • JonBJ JonB

          @ankou29666 said in QTreeView: Too many columns. What to do?:

          QSortFilterProxyModel should suit your needs to filter (or sort if ever needed) your columns.

          The OP appears (to me?) to want to hide columns. How would QSortFilterProxyModel ever hide a complete column (as opposed to showing the column with blank values in it)?

          I agree about proxy model which removes undesired columns, but I don't see QSortFilterProxyModel doing that (it can remove rows but not columns)?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @JonB i think it's the way I did it some time ago. But you're making me doubt. As far as I remember I did it (but with table model&view, not with tree !!!, this is maybe where I'm going wrong ?) with QSortFilterProxyModel and I think it was using filterAcceptColumn.

          1 Reply Last reply
          1
          • JonBJ JonB

            @ankou29666 said in QTreeView: Too many columns. What to do?:

            QSortFilterProxyModel should suit your needs to filter (or sort if ever needed) your columns.

            The OP appears (to me?) to want to hide columns. How would QSortFilterProxyModel ever hide a complete column (as opposed to showing the column with blank values in it)?

            I agree about proxy model which removes undesired columns, but I don't see QSortFilterProxyModel doing that (it can remove rows but not columns)?

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @JonB See QSortFilterProxyModel::filterAcceptsColumn() but tbh I never tested or used it :)

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @ankou29666 , @Christian-Ehrlicher
              You are both quite correct! I had never seen that, I thought it only had filterAcceptsRow(), it can do even more than I realised, my bad!

              1 Reply Last reply
              0
              • jeremy_kJ Offline
                jeremy_kJ Offline
                jeremy_k
                wrote on last edited by
                #7

                I lean toward QTreeView::setColumnHidden() rather than QSortFilterProxyModel::filterAcceptsColumn(), but either will work. Using a filter proxy will require a call to QSortFilterProxyModel::invalidate() or QSortFilterProxyModel::invalidateFilter() each time columns should be shown or hidden. Showing and hiding in the view rather than via a model might be more efficient.

                As for how to trigger it,

                Asking a question about code? http://eel.is/iso-c++/testcase/

                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