Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Blink a QAbstractItemModel Cell



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


  • Lifetime Qt Champion

    Hi,

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



  • @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).



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



  • This post is deleted!


  • @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.



  • @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?



  • 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



  • @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.



  • @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.



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



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



  • 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_);
    }
    

Log in to reply