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.

Qt Code:
  1. QVariant MyModel::data(const QModelIndex &item, int role) const
  2. {
  3. QVariant result = QSqlQueryModel::data(item, role);
  4.  
  5. int row = item.row();
  6. int col = item.column();
  7.  
  8. // generate a log message when this method gets called
  9. qDebug() << QString("row %1, col%2, role %3").arg(row).arg(col).arg(role);
  10.  
  11. switch(role){
  12. case Qt::BackgroundRole:
  13. if (row == active_row) // member active_row is set by a funciton call
  14. {
  15. QBrush redBackground(Qt::red);
  16. return redBackground;
  17. }
  18. break;
  19. }
  20.  
  21. return result;
  22. }
To copy to clipboard, switch view to plain text mode