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. [SOLVED] Persisiting QTreeView's header between model updates
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Persisiting QTreeView's header between model updates

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I'm migrating my project from QTreeWidget to QtreeView. With a widget there's no problem with the header - it lives as long as the widget does, so I just save its geometry and state to settings when quitting app and restoring when the app is starting.

    With QTreeView, however, it seems that I can only set header by doing model->setHorizontalHeaderLabels, and it has to be done again after model()->clear(), i. e. after every model update. So I'd have to recreate header view and store / restore its state and geometry every time. Is there a better way? Am I missing something?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can implement headerData in your custom model to return the headers for your view to show

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        Hi, thanks for the quick reply. I'm afraid that won't help. What I meant is persisiting header columns sizes, sort order, that kind of states. That must be done on view level, not model.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sorry I misunderstood what you said, you can then react on the modelAboutToBeReset signal, store the information you want to keep, then on reset you restore them

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            Thanks, that's exactly what I was looking for!

            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