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. Blink a QAbstractItemModel Cell

Blink a QAbstractItemModel Cell

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.3k 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.
  • R Offline
    R Offline
    raghaw
    wrote on last edited by
    #1

    Re: How to make cells blinking in a QTableView

    Solution mentioned in the link does not work for me...Can anybody help me in figuring out how to blink/flash a cell when some value is updated in it ?

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

      Hi,

      Are you going to have only one cell blinking at a time or will there be several ?

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

      R 1 Reply Last reply
      0
      • R raghaw

        Re: How to make cells blinking in a QTableView

        Solution mentioned in the link does not work for me...Can anybody help me in figuring out how to blink/flash a cell when some value is updated in it ?

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

        @raghaw
        I see that solution seems to change the background color between default and red. I have no idea whether this is better or worse (on the human eye), but I did it by alternating the Alpha in the RGBA value between 0 and 255. Which makes the foreground (number in my case) blink instead, doesn't use another color. Not that it makes much difference, but I allow for a list of items all of which are flashing (all changed values).

        R 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Are you going to have only one cell blinking at a time or will there be several ?

          R Offline
          R Offline
          raghaw
          wrote on last edited by
          #4

          the cell will blink when its value increases....I have QAbstractTableModel with m*n col, rows....
          In column 5th if any of cell value increases i need to notify the user that some value modification has happened through blink in cell for 1-2 secs.After 1-2 secs the color of the cell will become as original it was.

          JonBJ 1 Reply Last reply
          0
          • R raghaw

            the cell will blink when its value increases....I have QAbstractTableModel with m*n col, rows....
            In column 5th if any of cell value increases i need to notify the user that some value modification has happened through blink in cell for 1-2 secs.After 1-2 secs the color of the cell will become as original it was.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • JonBJ JonB

              @raghaw
              I see that solution seems to change the background color between default and red. I have no idea whether this is better or worse (on the human eye), but I did it by alternating the Alpha in the RGBA value between 0 and 255. Which makes the foreground (number in my case) blink instead, doesn't use another color. Not that it makes much difference, but I allow for a list of items all of which are flashing (all changed values).

              R Offline
              R Offline
              raghaw
              wrote on last edited by
              #6

              @JonB Any way to tell the user that something has changed by either changing alpha or blink will serve my purpose....
              How exactly u did that .Can you please let me know.

              JonBJ 2 Replies Last reply
              0
              • R raghaw

                @JonB Any way to tell the user that something has changed by either changing alpha or blink will serve my purpose....
                How exactly u did that .Can you please let me know.

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

                @raghaw
                I would have to look at code tomorrow. But in essence it will be like the link https://forum.qt.io/topic/4957/how-to-make-cells-blinking-in-a-qtableview/2 you quoted. It will just be a QTimer which (in my case) goes through a list I keep of blinking cells and changes their color. So what was it about that code which makes you say "Solution mentioned in the link does not work for me...", did you really write the code to implement it?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  raghaw
                  wrote on last edited by
                  #8

                  yes ...i am not able to figure out what should i put in datachanged signal....because since the blinking has to happen in fifth column

                  JonBJ 1 Reply Last reply
                  0
                  • R raghaw

                    yes ...i am not able to figure out what should i put in datachanged signal....because since the blinking has to happen in fifth column

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

                    @raghaw

                    In column 5th if any of cell value increases

                    .i am not able to figure out what should i put in datachanged signal....because since the blinking has to happen in fifth column

                    Sorry, but what is there to understand? If you get a dataChanged from any cell, then do your blinking in column 5 if that's what you want. If the row matters, then look at the row in the dataChanged and use the 5th column of that row. There's nothing else to show you.

                    1 Reply Last reply
                    0
                    • R raghaw

                      @JonB Any way to tell the user that something has changed by either changing alpha or blink will serve my purpose....
                      How exactly u did that .Can you please let me know.

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

                      @raghaw said in Blink a QAbstractItemModel Cell:

                      @JonB Any way to tell the user that something has changed by either changing alpha or blink will serve my purpose....
                      How exactly u did that .Can you please let me know.

                      You asked for my code here. I see that I did foreground flashing on the line edit in the spin box which are used to display my values, I'm not actually using a QTableView rather a QDataWidgetMapper to map from model to individual widgets. Nonetheless here is what I did about Alpha values to achieve that, as it may still be of interest to you (e.g. you could apply it in the data/setData() case for role == Qt::ForegroundRole of a model displayed in a QTableView):

                      /*static*/ void SectorRegisters::flashInvertColour(QSpinBox *spin, bool invert)
                      {
                          // if `invert` then "invert" the colour of (the line edit text) in a spin box
                          // else restore the colour to what it was before flashing started
                      
                          QLineEdit *lineEdit = UIUtils::spinBoxLineEdit(spin);
                          QPalette palette = lineEdit->palette();
                          QColor colour = palette.color(QPalette::Text);
                          // we do this by changing the text's alpha value between 255 (opaque, the default) and 0 (transparent)
                          int alpha = colour.alpha();
                          if (invert)
                              alpha = alpha ? 0 : 255;
                          else
                              alpha = 255;
                          colour.setAlpha(alpha);
                          palette.setColor(QPalette::Text, colour);
                          lineEdit->setPalette(palette);
                      }
                      

                      Of course, this in itself has nothing to do with your situation of wishing to do this on column #5, which is a separate issue and should not cause any problem.

                      1 Reply Last reply
                      1
                      • R Offline
                        R Offline
                        raghaw
                        wrote on last edited by
                        #11

                        @JonB i am able to blink in model cell but some times the blink happens after the value gets changed ...i mean the blink and condition for blink are not in sync....i am using a Qtimer of 10 msec

                        JonBJ 1 Reply Last reply
                        0
                        • R raghaw

                          @JonB i am able to blink in model cell but some times the blink happens after the value gets changed ...i mean the blink and condition for blink are not in sync....i am using a Qtimer of 10 msec

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

                          @raghaw
                          Don't know what you're seeing, and don't know what your code is.

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            raghaw
                            wrote on last edited by
                            #13
                            void setSpreadDetails(fp::tamktwatch::MktDataPerAgent& data, int32_t optionInstruId)
                            {
                            //Here iam updating the values 
                             int row = m_optionLocationInPortfolio[opName];
                              if(ommData.volToday > m_Data[m_optionLocationInPortfolio[opName]][(int)PortfolioCols::eCol_MVL].toInt())
                                     {             
                                        blinkCell_ = index(row, (int)PortfolioCols::eCol_MVL);
                                         emit dataChanged(blinkCell_, blinkCell_);
                                     }
                                    m_Data[m_optionLocationInPortfolio[opName]][(int)PortfolioCols::eCol_MVL] = QString::number(ommData.volToday);
                            }
                            

                            in Constructor i have one Qtimer :

                            PortfolioTableModel::PortfolioTableModel(TaCommAgent* inAgent, QObject* parent)
                                :QAbstractTableModel(parent)
                                , m_Agent(inAgent)
                            {   
                                connect(&blinkTimer_,SIGNAL(timeout()), this, SLOT(resetBlink()));
                                blinkTimer_.start(10);
                            }
                            

                            //In data function iam changing the values:

                            QVariant PortfolioTableModel::data(const QModelIndex& index, int role) const
                            {
                            if(role == Qt::BackgroundRole)
                            {
                                  if(srcIndex == blinkCell_ )
                                    {
                                       return QBrush( QColor( Qt::yellow ) );
                                    }
                                    return QBrush(LIGHT_BLUE);
                            }
                            }
                            

                            And in resetBlink iam resting the modelindex

                            void PortfolioTableModel::resetBlink()
                            {
                                blinkCell_ = QModelIndex();
                                emit dataChanged(blinkCell_, blinkCell_);
                            }
                            
                            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