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. Header from tableview doesnt update after sorting
Qt 6.11 is out! See what's new in the release blog

Header from tableview doesnt update after sorting

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 2.6k 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.
  • M Offline
    M Offline
    Maser
    wrote on last edited by
    #1

    Hi.
    When i sort my tableview the header doesnt update until i hover wiht the mouse over each header cell. Why?

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

      Hi,

      Are you using a custom model ?

      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
      • M Offline
        M Offline
        Maser
        wrote on last edited by Maser
        #3

        Indeed i do. Im doing the sorting trough resetting the model data.

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

          Reset the model ?

          Are you also re-implementing the headerData method ?

          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
          • M Offline
            M Offline
            Maser
            wrote on last edited by
            #5

            Yes, with emit beginresetmodel and endresetmodel. I need my model updated every second.

            Yes, like this

                if (role != Qt::DisplayRole)
                    return QVariant();
                if ( orientation == Qt::Vertical )
                {
                     ...
                    return bla;
                }
                if(orientation == Qt::Horizontal)
                {
                    if(section == 0)
                    {
                        return blabla1
                    }
                    if(section == 1)
                    {
                        return blabla2
                    }
            
                }
            
                return QVariant();
            
            raven-worxR 1 Reply Last reply
            0
            • M Maser

              Yes, with emit beginresetmodel and endresetmodel. I need my model updated every second.

              Yes, like this

                  if (role != Qt::DisplayRole)
                      return QVariant();
                  if ( orientation == Qt::Vertical )
                  {
                       ...
                      return bla;
                  }
                  if(orientation == Qt::Horizontal)
                  {
                      if(section == 0)
                      {
                          return blabla1
                      }
                      if(section == 1)
                      {
                          return blabla2
                      }
              
                  }
              
                  return QVariant();
              
              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Maser
              instead of resetting the whole model (when it's not necessary) you should only emit the changed signals of the data which has actually changed. And let Qt do the optimization.

              So emit headerDataChanged() instead.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1
              • M Offline
                M Offline
                Maser
                wrote on last edited by
                #7

                It is necessary because i need the view updated every second, and yes, all data changes every second cause it is calculated data i receive from the model, bound on current time.
                But thanks, emmiting headerdatachanged helped.

                raven-worxR 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Even if all the data is changed, you can emit a dataChanged for the whole model.

                  resetModel is usually used when the model layout changes, which doesn't seems to be your case.

                  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
                  • M Maser

                    It is necessary because i need the view updated every second, and yes, all data changes every second cause it is calculated data i receive from the model, bound on current time.
                    But thanks, emmiting headerdatachanged helped.

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    @Maser
                    to add up to @SGaist
                    a model reset is more radical approach of telling the view that the data has changed.
                    A model reset implies that the selection and current gets lost, the current scroll position is reset, ...
                    So you should only reset (also from the user experience point of view) when the structure of the model changes. But as long as just the "content" of existing items change you should emit the dataChanged() signal instead.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Maser
                      wrote on last edited by Maser
                      #10

                      My bad. I use dataChanged, like SGaist hinted in another thread. Was just a bit confused in my own code))
                      But dataChanged doesnt update header when the table is sorted, while headerDataChanged does.

                      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