Hello cjhuitt
Iám confused about the setData en data methods for my custom role (IsBlinkingRole).
I try different options but every option failled.
bool CustomSqlModel::setData( const QModelIndex& index, const QVariant& value, int role)
{
if (role == IsBlinkingRole && index.column() == 0 && index.isValid()) {
//What to put here ?
emit dataChanged(index, index);
return true;
}
return false;
QVariant CustomSqlModel::data(const QModelIndex& index, int role) const
{
QVariant value = QSqlTableModel::data(index, role);
if (role == Qt::BackgroundRole && index.column() == 0) {
QModelIndex testIndex = index.model()->index(index.row(), 0, index.parent());
if ( index.model()->data(testIndex, Qt::DisplayRole).toInt() == 5)
return QVariant(QColor(Qt::red));
else
return QVariant();
}
return value;
}
void CustomSqlModel::timerEvent(QTimerEvent *)
{
static bool blinkon = true;
blinkon = !blinkon;
int topRow = rowCount();
int bottomRow = -1;
for(int i = 0; i < rowCount(); i++) {
for(int j = 0; j < 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 < topRow) topRow = i; if(i > bottomRow) bottomRow = i;
}
}
}
if(bottomRow >= 0)
emit dataChanged(index(topRow, 0), index(bottomRow, columnCount()-1));
}
Thanks cjhuitt for your time and advice.
If i can't solved this then i let the blinking cell for what it is.
First of all my apology for asking three times the same question.
Iám new in stackoverflow.
The problem i have with the setData method wat kind of code i need to put here.
Must i first create a container for storage data ?
Thank in advance.