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. Blinking line in QListView/QTableView/QTreeView
Qt 6.11 is out! See what's new in the release blog

Blinking line in QListView/QTableView/QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 5.7k Views 2 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.
  • S ShinSat

    Hi Gurus,

    I'm not succeeding in implementation of blinking line(row) in QTreeView.
    Is there anybody who experienced this? Is it about StyleSheet?
    I just want to blink(and reset later) lines in QListView/QTableView/QTreeView.

    Any pointers to right direction is welcome.

    Many thanks in advance for your help.
    Regards,
    Sat

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

    @ShinSat said in Blinking line in QListView/QTableView/QTreeView:

    Any pointers to right direction is welcome.

    • return the color from your model for the Qt::BackgroundRole for the corresponding indexes
    • use a timer which toggles the state and triggers a dataChanged() signal in the model (for the whole row)

    --- 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

    S 2 Replies Last reply
    0
    • raven-worxR raven-worx

      @ShinSat said in Blinking line in QListView/QTableView/QTreeView:

      Any pointers to right direction is welcome.

      • return the color from your model for the Qt::BackgroundRole for the corresponding indexes
      • use a timer which toggles the state and triggers a dataChanged() signal in the model (for the whole row)
      S Offline
      S Offline
      ShinSat
      wrote on last edited by
      #3

      Thanks for an update, @raven-worx
      Is this an idea about assigning one timer to each row?

      Sat

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #4
        • subclass the view
        • add a private timer that takes care of timing the blinking and a boolean that keeps track of the state of the blink
        • connect the timer timeout to the view's update and a slot that inverts the boolean
        • reimplement viewOptions() calling the base class implementation and then changing the backgroundBrush property of the result based on the boolean value

        "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

        1 Reply Last reply
        1
        • S Offline
          S Offline
          ShinSat
          wrote on last edited by
          #5

          Thank you very much for your help, all.
          Here, I'm also trying using QPropertyAnimation but no luck so far... :<
          I would like to share a proven, stable, and light weight implementaion.

              def make_blink_wgt(self, obj):
                  eEffect = QGraphicsColorizeEffect(obj)
                  obj.setGraphicsEffect(eEffect)
          
                  anim = QPropertyAnimation(eEffect, b'color')
                  anim.setDuration(1000)
                  anim.setLoopCount(30)
                  anim.setStartValue(obj.palette().text().color())
                  anim.setEndValue(obj.palette().text().color())
                  anim.setKeyValueAt(0.5, QColor(0, 255, 0))
          
                  anim.start()
          
          1 Reply Last reply
          0
          • S Offline
            S Offline
            ShinSat
            wrote on last edited by ShinSat
            #6

            One thing I'm not sure is the cost of the implementation. Since my display items are going to be huge(eg. tens of thousands). What do you think about the difference between subclassing View and Model?
            Of course, I don't mean every item to be blinked. These are, for example, just newly added items and the ones which are dynamically evaluated in run time as important items.

            BTW, signaling dataChanged in the View affects the whole items, which is a big cost, isn't it?

            Sat

            1 Reply Last reply
            0
            • raven-worxR raven-worx

              @ShinSat said in Blinking line in QListView/QTableView/QTreeView:

              Any pointers to right direction is welcome.

              • return the color from your model for the Qt::BackgroundRole for the corresponding indexes
              • use a timer which toggles the state and triggers a dataChanged() signal in the model (for the whole row)
              S Offline
              S Offline
              ShinSat
              wrote on last edited by ShinSat
              #7

              @raven-worx

              return the color from your model for the Qt::BackgroundRole for the corresponding indexes
              use a timer which toggles the state and triggers a dataChanged() signal in the model (for the whole row)

              I'm testing the idea you shared in pyqt5.9.1 on Win7 and not succeeding in emitting dataChanged().
              Are you able to share an example?

              Sat

              S 1 Reply Last reply
              0
              • S ShinSat

                @raven-worx

                return the color from your model for the Qt::BackgroundRole for the corresponding indexes
                use a timer which toggles the state and triggers a dataChanged() signal in the model (for the whole row)

                I'm testing the idea you shared in pyqt5.9.1 on Win7 and not succeeding in emitting dataChanged().
                Are you able to share an example?

                Sat

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

                @ShinSat Regarding emitting dataChanged, I testing a timer, called watch_dog, emitting dataChanged signal in the model. But nothing happend in the list. What am I misunderstanding?? :<<
                How can I explicitly invoke BackgroundRole in data() in the model?

                    def watch_dog(self):
                        print('Bow')
                        th = threading.Timer(TIMER, self.watch_dog)
                        th.start()
                      # do something here
                        self.dataChanged.emit(self.createIndex(2, 0), self.createIndex(2, 2))
                
                

                Update:
                self.modelReset.emit() , instead of dataChanged.emit(), works. Strange..Why dataChanged() does not update the view in real time.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  ShinSat
                  wrote on last edited by
                  #9

                  Looks like I'm trying to update with dataChanged in the MODEL, but the VIEW should be refreshed instead, am I right?

                  Sat

                  raven-worxR 1 Reply Last reply
                  0
                  • S ShinSat

                    Looks like I'm trying to update with dataChanged in the MODEL, but the VIEW should be refreshed instead, am I right?

                    Sat

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

                    @ShinSat said in Blinking line in QListView/QTableView/QTreeView:

                    Looks like I'm trying to update with dataChanged in the MODEL, but the VIEW should be refreshed instead, am I right?

                    with the dataChanged() signal you tell the view that the data has changed and that is need to update itself. Other than the reset() signal, the dataChanged() signal doesn't clear selections.

                    So i guess your model index parameters are incorrect at the time you emit the dataChanged() signal?
                    (The indexes are 0-based of course)

                    --- 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

                    S 1 Reply Last reply
                    0
                    • raven-worxR raven-worx

                      @ShinSat said in Blinking line in QListView/QTableView/QTreeView:

                      Looks like I'm trying to update with dataChanged in the MODEL, but the VIEW should be refreshed instead, am I right?

                      with the dataChanged() signal you tell the view that the data has changed and that is need to update itself. Other than the reset() signal, the dataChanged() signal doesn't clear selections.

                      So i guess your model index parameters are incorrect at the time you emit the dataChanged() signal?
                      (The indexes are 0-based of course)

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

                      Thank you very much for your help, @raven-worx.
                      I found that I was calling the MODEL's datachanged, but it worked when I called VIEW's one.
                      Yes, I think it was my fault. I need some more tests but it should be OK. :)

                      BTW, one thing I'm still not sure is the cost of updating the view with timer because my data will be tens of thousands...

                      Sat

                      raven-worxR 1 Reply Last reply
                      0
                      • S ShinSat

                        Thank you very much for your help, @raven-worx.
                        I found that I was calling the MODEL's datachanged, but it worked when I called VIEW's one.
                        Yes, I think it was my fault. I need some more tests but it should be OK. :)

                        BTW, one thing I'm still not sure is the cost of updating the view with timer because my data will be tens of thousands...

                        Sat

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

                        @ShinSat said in Blinking line in QListView/QTableView/QTreeView:

                        BTW, one thing I'm still not sure is the cost of updating the view with timer because my data will be tens of thousands...

                        depends.
                        Of course you should only use a single timer for all rows, not a timer for each row.
                        First implement it and then get rid of the possible bootlenecks

                        --- 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

                        • Login

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