Quote Originally Posted by linoprit View Post
So, I have nothing to do with setting the color in the application code. All that must be done is to set the active row.

Qt Code:
  1. void MyModel::setActiveRow(int row) // called from slot doubleClick
  2. {
  3. active_row = row;
  4. }
To copy to clipboard, switch view to plain text mode 
This method changes the model's data, i.e. MyModel::data() returns different values after that call changed active_row.
So naturally it is the place to emit change signals.

Qt Code:
  1. void MyModel::setActiveRow(int row)
  2. {
  3. if (active_row == row)
  4. return; // no change
  5.  
  6. int oldRow = active_row;
  7. active_row = row;
  8.  
  9. // de-highlight previously active row
  10. if (oldRow > -1) {
  11. QModelIndex rowBegin = index(oldRow, 0);
  12. QModelIndex rowEnd = index(oldRow, columnCount() - 1);
  13. emit dataChanged(rowBegin, rowEnd);
  14. }
  15.  
  16. // highlight newly active row
  17. if (row > -1) {
  18. QModelIndex rowBegin = index(row, 0);
  19. QModelIndex rowEnd = index(row, columnCount() - 1);
  20. emit dataChanged(rowBegin, rowEnd);
  21. }
  22. }
To copy to clipboard, switch view to plain text mode 

Cheers,
_