Hi everybody,
I'm struggling around with a propably simple problem. I use a QSqlQueryModel to display some data. When a cell is double-clicked, the whole row should be marked by changing the background color. This is done by reimplementing the model and overload the data function.
But: when another row is double-clicked the previous coloured row stays marked (but should not). When a button is clicked, or the window is resized, the marking vanishes.
Can I emit some signal to redraw the table view? What happens, when a button is clicked - can I do the same?
I also tried to emit dataChanged and layoutChanged signals from within the data function, but because it's const this seems not to work (compiler complains: passing 'const MyModel' as 'this' argument of 'void QAbstractItemModel::layoutChanged()' discards qualifiers [-fpermissive])
Also I tried repaint(), it had no effect.
{
int row = item.row();
int col = item.column();
// generate a log message when this method gets called
qDebug
() <<
QString("row %1, col%2, role %3").
arg(row
).
arg(col
).
arg(role
);
switch(role){
case Qt::BackgroundRole:
if (row == active_row) // member active_row is set by a funciton call
{
QBrush redBackground
(Qt
::red);
return redBackground;
}
break;
}
return result;
}
QVariant MyModel::data(const QModelIndex &item, int role) const
{
QVariant result = QSqlQueryModel::data(item, role);
int row = item.row();
int col = item.column();
// generate a log message when this method gets called
qDebug() << QString("row %1, col%2, role %3").arg(row).arg(col).arg(role);
switch(role){
case Qt::BackgroundRole:
if (row == active_row) // member active_row is set by a funciton call
{
QBrush redBackground(Qt::red);
return redBackground;
}
break;
}
return result;
}
To copy to clipboard, switch view to plain text mode
Bookmarks