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. How to efficiently emit dataChanged signal?
Forum Updated to NodeBB v4.3 + New Features

How to efficiently emit dataChanged signal?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 3.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.
  • VRoninV VRonin

    if paining the unchanged cells is expensive then yes, individual dataChanged for each item is the way to go. The range method will just trigger a total repaint of the view(port) (unless you are using a custom view)

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

    @VRonin said in How to efficiently emit dataChanged signal?:

    The range method will just trigger a total repaint of the view(port)

    Interesting. You are saying that dataChanged(index(0, 0), index (0, 1)) (any range, smallest) is implemented in attached QTableView as complete, all-cells/viewport repaint; no attempt is made in code to recognise 2-cell range and treat as 2-cell repaint as dataChanged(index(0, 0), index (0, 0)); dataChanged(index(0, 1), index (0, 1)); would be? Or, indeed, are the multiple separate ones buffered for repaint anyway and if more than a single cell always repaints completely?

    Not complaining, just would like to know the internal behaviour (preferably without you telling me to look thru the source for myself!).

    VRoninV 1 Reply Last reply
    0
    • JonBJ JonB

      @VRonin said in How to efficiently emit dataChanged signal?:

      The range method will just trigger a total repaint of the view(port)

      Interesting. You are saying that dataChanged(index(0, 0), index (0, 1)) (any range, smallest) is implemented in attached QTableView as complete, all-cells/viewport repaint; no attempt is made in code to recognise 2-cell range and treat as 2-cell repaint as dataChanged(index(0, 0), index (0, 0)); dataChanged(index(0, 1), index (0, 1)); would be? Or, indeed, are the multiple separate ones buffered for repaint anyway and if more than a single cell always repaints completely?

      Not complaining, just would like to know the internal behaviour (preferably without you telling me to look thru the source for myself!).

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #4

      @JonB said in How to efficiently emit dataChanged signal?:

      u are saying that dataChanged(index(0, 0), index (0, 1)) (any range, smallest) is implemented in attached QTableView as complete, all-cells/viewport repaint;

      Yes, you can see a discussion on the topic here: https://forum.qt.io/topic/89623/ideas-to-optimise-qabstractitemview-datachanged

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      JonBJ 1 Reply Last reply
      3
      • VRoninV VRonin

        @JonB said in How to efficiently emit dataChanged signal?:

        u are saying that dataChanged(index(0, 0), index (0, 1)) (any range, smallest) is implemented in attached QTableView as complete, all-cells/viewport repaint;

        Yes, you can see a discussion on the topic here: https://forum.qt.io/topic/89623/ideas-to-optimise-qabstractitemview-datachanged

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

        @VRonin
        Thanks for that link. I don't have time to read through 24-odd replies! Something basic like "if the cell range is "small" compared to the complete row/columns size do it by individual cell repaint" might (or might not!) be worthwhile. When my changed cell range is 1x2, say, that might improve when the table view is 100x100? :)

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #6

          It all depends how many are actually within the viewport and how expensive is to calculate where they are. That's why we got stuck, there is no good answer unless you know with high confidence what is being displayed.

          The quick answer is: if the number of cells changed is > the number of cells "normally" visible then just use a range and repaint it all.
          If you don't the view would have to calculate the rect of each item changed and that is almost as expensive as painting it so even if they are off screen it will be costly.

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          JonBJ 1 Reply Last reply
          0
          • VRoninV VRonin

            It all depends how many are actually within the viewport and how expensive is to calculate where they are. That's why we got stuck, there is no good answer unless you know with high confidence what is being displayed.

            The quick answer is: if the number of cells changed is > the number of cells "normally" visible then just use a range and repaint it all.
            If you don't the view would have to calculate the rect of each item changed and that is almost as expensive as painting it so even if they are off screen it will be costly.

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

            @VRonin said in How to efficiently emit dataChanged signal?:

            The quick answer is: if the number of cells changed is > the number of cells "normally" visible then just use a range and repaint it all.

            That sounds fine. But earlier you said

            The range method will just trigger a total repaint of the view(port) (unless you are using a custom view)

            First way look at number of cells changed to decide whether individually or whole repaint, second way always claims to do whole repaint regardless of how many cells in range/total.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #8

              I did a little tweaking for Qt6: https://codereview.qt-project.org/c/qt/qtbase/+/285280

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

              VRoninV 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                I did a little tweaking for Qt6: https://codereview.qt-project.org/c/qt/qtbase/+/285280

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #9

                @Christian-Ehrlicher Oh, brutal... I'm not sure it's a straight improvement when topLeft!=bottomRight. This calculates visualRect for the entire range + painting those in the viewport. It's not a cheap operation. It might well be that repainting the entire viewport might be cheaper. Am I missing something here?

                Edit:
                I even commented on the code review. Man my memory is toying with me

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                Christian EhrlicherC 1 Reply Last reply
                0
                • VRoninV VRonin

                  @Christian-Ehrlicher Oh, brutal... I'm not sure it's a straight improvement when topLeft!=bottomRight. This calculates visualRect for the entire range + painting those in the viewport. It's not a cheap operation. It might well be that repainting the entire viewport might be cheaper. Am I missing something here?

                  Edit:
                  I even commented on the code review. Man my memory is toying with me

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

                  @VRonin said in How to efficiently emit dataChanged signal?:

                  It might well be that repainting the entire viewport might be cheaper. Am I missing something here?

                  As always - it depends.
                  The problem is that you can't simply use the first topLeft and last bottomRight coordinates since they might be reordered. But it should be enough to calculate only the ones marked with 'x' here:

                  x x x x
                  x 0 0 0
                  x 0 0 0

                  even if they are reordered we can be sure to get topLeft and bottomRight coordinates - or am I wrong?

                  x 0 0 0
                  x x x x
                  x 0 0 0

                  0 0 x 0
                  x x x x
                  0 0 x 0

                  and QAIV::dataChanged() is virtual so everyone can add it's own logic depending on the use case if it's really a bottleneck.

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

                  VRoninV 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @VRonin said in How to efficiently emit dataChanged signal?:

                    It might well be that repainting the entire viewport might be cheaper. Am I missing something here?

                    As always - it depends.
                    The problem is that you can't simply use the first topLeft and last bottomRight coordinates since they might be reordered. But it should be enough to calculate only the ones marked with 'x' here:

                    x x x x
                    x 0 0 0
                    x 0 0 0

                    even if they are reordered we can be sure to get topLeft and bottomRight coordinates - or am I wrong?

                    x 0 0 0
                    x x x x
                    x 0 0 0

                    0 0 x 0
                    x x x x
                    0 0 x 0

                    and QAIV::dataChanged() is virtual so everyone can add it's own logic depending on the use case if it's really a bottleneck.

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #11

                    @Christian-Ehrlicher said in How to efficiently emit dataChanged signal?:

                    or am I wrong?

                    If the first row/column is hidden you are f***ed.
                    I think what you did is totally correct. I'm just not convinced is that much of a step up vs the previous

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • VRoninV VRonin

                      @Christian-Ehrlicher said in How to efficiently emit dataChanged signal?:

                      or am I wrong?

                      If the first row/column is hidden you are f***ed.
                      I think what you did is totally correct. I'm just not convinced is that much of a step up vs the previous

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

                      @VRonin It simply depends on the usecase - if they're not visible and there are not much cells in the range than mine is faster.

                      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
                      1

                      • Login

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