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 setRootIndex & changing header - incorrect columnCount...?

QTreeView setRootIndex & changing header - incorrect columnCount...?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeviewqheaderview
6 Posts 3 Posters 1.2k Views
  • 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 5 May 2019, 05:24 last edited by Dariusz 5 May 2019, 05:24
    #1

    Hey

    So I have a bit of a "sigh" moment, I'm trying to implement setRootIndex & change header data at the same time.

    The changing of header "text" seems to work, however, the count of items seem to not work. I ensure that the columnCount on old rootIndex and new rootIndex return proper column count, and I can see it in print as well during columnCount() call, but the number of columns doesn't change. What am I missing here?

    Regards
    Dariusz

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 5 May 2019, 06:30 last edited by
      #2

      Possibly calls to beginInsertColumns or beginRemoveColumns are missing.

      setRootIndex() will cause a model reset, but if you change header after that, the view won't know that column count has changed.

      (Z(:^

      D 1 Reply Last reply 5 May 2019, 07:21
      0
      • S sierdzio
        5 May 2019, 06:30

        Possibly calls to beginInsertColumns or beginRemoveColumns are missing.

        setRootIndex() will cause a model reset, but if you change header after that, the view won't know that column count has changed.

        D Offline
        D Offline
        Dariusz
        wrote on 5 May 2019, 07:21 last edited by
        #3

        @sierdzio hmm yeah which is the problem. I change header before changing rootIndex. I mean, the header is taken dynamically from root index, right?

        I mean:

        invisibleRootItem.data = header text items.
        So if I change invisibleRootItem.data = newHeader.data.
        it should be a new header? I mean I know it works because it returns the correct number of columnCount & header display new text, but header doesn't add/remove columns... depending on data.size() which is what it being used to determine column draw? I must be missing something.. sigh.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 5 May 2019, 07:35 last edited by
          #4

          Number of columns is a property of the model, not the header. So your model needs to return correct columnCount(). And if the count changes, model has to notify the views (by begin/end methods, resetModel or dataChanged).

          (Z(:^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 5 May 2019, 07:38 last edited by
            #5

            Using setRootIndex() only works reliable when the header count does not change and imo is not meant for anything else, see also https://bugreports.qt.io/browse/QTBUG-40560
            I would be happy to get this stuff removed since it's just causing trouble for all use cases where more than the root index should change - all this can be (re)implemented with a second model or a QSortFilterProxyModel or similar.

            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
            • D Offline
              D Offline
              Dariusz
              wrote on 5 May 2019, 10:09 last edited by Dariusz 5 May 2019, 10:17
              #6

              I'm using abstractItemModel / my own item, I ensure that columnCount return correct number of columns, yet it's still wrong.

              In regard to using proxyModels, I'd love to use it, but I only found few examples and I'm struggling as to how I would do it. Any hints wold be great, I would prefer to use a proxy instead here.

              I literally have no idea how I can simulate setRootIndex with proxyModel, since I need to see parentItem of the item that I wish to set as rootitem and I don't want to see these parent items... here was me early attempt > https://forum.qt.io/topic/102227/qsortfilterproxymodel-simulate-new-root-index/2

              @Christian-Ehrlicher I'm totally blaming you for me going this setRootIndex road as I was trying proxy early and you said to use this : p

              1 Reply Last reply
              0

              1/6

              5 May 2019, 05:24

              • Login

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