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. draw back item(s) in the same row?
Forum Update on Monday, May 27th 2025

draw back item(s) in the same row?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.5k 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.
  • S Offline
    S Offline
    ShinSat
    wrote on last edited by
    #1

    Hi All,

    I have a custom delegate (QStyledItemDelegate) used with Qtreeview/QStandardItemModel.
    Now I want to draw each cell in the view based on later contents. For example, if colum:2 is 'ABC', the color of whole row will be changed, which means colum:0,1,2,3,,, will be all changed.
    I know delegate works sequencially from colum0 to columN, but would like to know if I can draw back the column0 during the drawing process of column1.

    Thanks for your help.
    Sat

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

      Hi,

      Why not do it directly in the cell drawing code ? You can check for sibling values when painting.

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

      S 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Why not do it directly in the cell drawing code ? You can check for sibling values when painting.

        S Offline
        S Offline
        ShinSat
        wrote on last edited by ShinSat
        #3

        @SGaist said in draw back item(s) in the same row?:

        Why not do it directly in the cell drawing code ? You can check for sibling values when painting.

        Sorry, but could you tell me a way to read siblings in paint()? Specifying a specific index?

        Update:

           def paint(self, paint, option, index):
                text = index.model().data(index)
                print(text)
                print(index.row())
                if index.column() == 1:
                    prev_text = self.parent.view.model().index(index.row(), 0).data()
                QStyledItemDelegate.paint(self, paint, option, index)
        

        OK, something like this?
        self.parent.view.model().index(index.row(), 0).data()
        But is it possible to re-draw a column, which is already drawn?

        Sat

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

          http://doc.qt.io/qt-5/qabstractitemmodel.html#sibling

          index.model()->sibling(index.row(),someOtherColum,index);

          "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

          S 1 Reply Last reply
          1
          • VRoninV VRonin

            http://doc.qt.io/qt-5/qabstractitemmodel.html#sibling

            index.model()->sibling(index.row(),someOtherColum,index);

            S Offline
            S Offline
            ShinSat
            wrote on last edited by ShinSat
            #5

            @VRonin said in draw back item(s) in the same row?:

            ex.model()->sibling(index.row(),someOtherColum,index);

            Thanks for your help.
            SO,,, it returns an QModelIndex to someOtherColum in the same row so that I can read another column with the gotten QModelIndex like index.model().data(NewlyGottenIndex), right?
            Anyway, it's working here on my env. :)

            Now, I need to find a way to re-draw a column in paint(), which is already drawn by the previous paint() call...:<

            Sat

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

              Why ? The delegate is responsible for the painting.

              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
              • S ShinSat

                @VRonin said in draw back item(s) in the same row?:

                ex.model()->sibling(index.row(),someOtherColum,index);

                Thanks for your help.
                SO,,, it returns an QModelIndex to someOtherColum in the same row so that I can read another column with the gotten QModelIndex like index.model().data(NewlyGottenIndex), right?
                Anyway, it's working here on my env. :)

                Now, I need to find a way to re-draw a column in paint(), which is already drawn by the previous paint() call...:<

                Sat

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

                @ShinSat

                Now, I need to find a way to re-draw a column in paint(), which is already drawn by the previous paint() call...:<

                I think you're thinking the wrong way round. Are you thinking you must wait till you reach & paint the later columns which determine the color before you can then (go back and) re-paint the earlier columns? I believe the experts are suggesting you use the sibling() in the earlier columns to read the value in the later column to determine their color, without waiting till the later columns get drawn.

                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