Note that there are some explanatory texts on larger screens.

plurals
  1. POBlinking background cell in a model
    text
    copied!<p>I am confused about the <code>setData</code> in data methods for my custom role (<code>IsBlinkingRole</code>). I've tried different options but every option failed.</p> <pre><code>bool CustomSqlModel::setData( const QModelIndex&amp; index, const QVariant&amp; value, int role) { if (role == IsBlinkingRole &amp;&amp; index.column() == 0 &amp;&amp; index.isValid()) { //What to put here ? emit dataChanged(index, index); return true; } return false; QVariant CustomSqlModel::data(const QModelIndex&amp; index, int role) const { QVariant value = QSqlTableModel::data(index, role); if (role == Qt::BackgroundRole &amp;&amp; index.column() == 0) { QModelIndex testIndex = index.model()-&gt;index(index.row(), 0, index.parent()); if ( index.model()-&gt;data(testIndex, Qt::DisplayRole).toInt() == 5) return QVariant(QColor(Qt::red)); else return QVariant(); } return value; </code></pre> <p>}</p> <pre><code> void CustomSqlModel::timerEvent(QTimerEvent *) { static bool blinkon = true; blinkon = !blinkon; int topRow = rowCount(); int bottomRow = -1; for(int i = 0; i &lt; rowCount(); i++) { for(int j = 0; j &lt; columnCount(); j++) { if(data(index(i, j), IsBlinkingRole).toBool()){ if(blinkon) setData(index(i, j), Qt::red, Qt::BackgroundRole); else setData(index(i, j), QVariant(), Qt::BackgroundRole); if(i &lt; topRow) topRow = i; if(i &gt; bottomRow) bottomRow = i; } } } if(bottomRow &gt;= 0) emit dataChanged(index(topRow, 0), index(bottomRow, columnCount()-1)); </code></pre> <p>}</p> <p>The problem I have with the <code>setData</code> method is regarding what kind of code I need to put here. </p> <p>Do I have to create a container first to store data? </p> <p><sub>Sidenote: Thanks cjhuitt for your time and advice.<br> If I can't solve this then I will leave the blinking cell.<br> My apologies for asking three times the same question.<br> I am new to stackoverflow.</sub> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload