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. Signal flag changes for QAbstractItemModel
Forum Update on Monday, May 27th 2025

Signal flag changes for QAbstractItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
itemmodel
18 Posts 4 Posters 3.6k 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.
  • J JonB
    3 May 2023, 20:51

    @SGaist
    dataChanged() does not really convey that. But as @kshegunov said there isn't a role for "flags". I imagine DisplayRole will have the desired effect of forcing it to re-evaluate the flag()s and see e.g. item enablement change, so you would get the desired behaviour for the wrong reason.

    S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 3 May 2023, 20:53 last edited by
    #8

    @JonB maybe coupled with EditRole since the flag change might also influence that part.

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

    J 1 Reply Last reply 3 May 2023, 20:55
    0
    • S SGaist
      3 May 2023, 20:53

      @JonB maybe coupled with EditRole since the flag change might also influence that part.

      J Offline
      J Offline
      JonB
      wrote on 3 May 2023, 20:55 last edited by
      #9

      @SGaist Do a dataChanged() for "all roles" and then you have done the best you can :)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 5 May 2023, 18:55 last edited by
        #10

        I am sure there are some corner cases that will be fun

        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
        • K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 6 May 2023, 08:13 last edited by
          #11

          Well, I'd long forgotten about this topic, but I would think we actually need a flagsChanged(QModelIndex, QModelIndex) signal, which would be "the right way"™. I didn't open a feature request at the time, but maybe one of you might feel strongly enough about it to do so.

          Read and abide by the Qt Code of Conduct

          J 1 Reply Last reply 6 May 2023, 08:21
          1
          • K kshegunov
            6 May 2023, 08:13

            Well, I'd long forgotten about this topic, but I would think we actually need a flagsChanged(QModelIndex, QModelIndex) signal, which would be "the right way"™. I didn't open a feature request at the time, but maybe one of you might feel strongly enough about it to do so.

            J Offline
            J Offline
            JonB
            wrote on 6 May 2023, 08:21 last edited by
            #12

            @kshegunov
            It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response? And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

            K 1 Reply Last reply 6 May 2023, 08:24
            0
            • J JonB
              6 May 2023, 08:21

              @kshegunov
              It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response? And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 6 May 2023, 08:24 last edited by
              #13

              @JonB said in Signal flag changes for QAbstractItemModel:

              It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response?

              It should be painless in the sense that it's a new signal, so nobody needs to actually do anything to keep old code working.

              And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

              Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

              Read and abide by the Qt Code of Conduct

              J 1 Reply Last reply 6 May 2023, 08:32
              0
              • K kshegunov
                6 May 2023, 08:24

                @JonB said in Signal flag changes for QAbstractItemModel:

                It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response?

                It should be painless in the sense that it's a new signal, so nobody needs to actually do anything to keep old code working.

                And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

                Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

                J Offline
                J Offline
                JonB
                wrote on 6 May 2023, 08:32 last edited by
                #14

                @kshegunov said in Signal flag changes for QAbstractItemModel:

                Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

                Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                K 1 Reply Last reply 6 May 2023, 08:37
                0
                • J JonB
                  6 May 2023, 08:32

                  @kshegunov said in Signal flag changes for QAbstractItemModel:

                  Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

                  Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                  K Offline
                  K Offline
                  kshegunov
                  Moderators
                  wrote on 6 May 2023, 08:37 last edited by
                  #15

                  @JonB said in Signal flag changes for QAbstractItemModel:

                  Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                  It may, which was my original argument - it (the signal) could simply do nothing significant in the end.

                  Read and abide by the Qt Code of Conduct

                  S 1 Reply Last reply 6 May 2023, 19:11
                  0
                  • K kshegunov
                    6 May 2023, 08:37

                    @JonB said in Signal flag changes for QAbstractItemModel:

                    Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                    It may, which was my original argument - it (the signal) could simply do nothing significant in the end.

                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 6 May 2023, 19:11 last edited by
                    #16

                    I wonder how often this use case happens.

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

                    K 1 Reply Last reply 9 May 2023, 08:42
                    1
                    • S SGaist
                      6 May 2023, 19:11

                      I wonder how often this use case happens.

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 9 May 2023, 08:42 last edited by
                      #17

                      @SGaist said in Signal flag changes for QAbstractItemModel:

                      I wonder how often this use case happens.

                      I'd imagine for any nontrivial use of the item model, this will happen. In the case of widgets it probably won't matter anyway, as you'd want to immediately redraw whatever it is you're showing; but with Qt quick it may actually be a malice on performance, since it would invalidate the scene graph node (which may or may not be a problem, I haven't actually looked at the implementation).

                      Read and abide by the Qt Code of Conduct

                      J 1 Reply Last reply 9 May 2023, 08:48
                      0
                      • K kshegunov
                        9 May 2023, 08:42

                        @SGaist said in Signal flag changes for QAbstractItemModel:

                        I wonder how often this use case happens.

                        I'd imagine for any nontrivial use of the item model, this will happen. In the case of widgets it probably won't matter anyway, as you'd want to immediately redraw whatever it is you're showing; but with Qt quick it may actually be a malice on performance, since it would invalidate the scene graph node (which may or may not be a problem, I haven't actually looked at the implementation).

                        J Offline
                        J Offline
                        JonB
                        wrote on 9 May 2023, 08:48 last edited by
                        #18

                        @kshegunov
                        One might actually need the signal to tell us which flags have changed. Only certain flag changes affect anything we are interested in, several seem not relevant.

                        1 Reply Last reply
                        0

                        17/18

                        9 May 2023, 08:42

                        • Login

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