
Originally Posted by
linoprit
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.
void MyModel::setActiveRow(int row) // called from slot doubleClick
{
active_row = row;
}
void MyModel::setActiveRow(int row) // called from slot doubleClick
{
active_row = row;
}
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.
void MyModel::setActiveRow(int row)
{
if (active_row == row)
return; // no change
int oldRow = active_row;
active_row = row;
// de-highlight previously active row
if (oldRow > -1) {
emit dataChanged(rowBegin, rowEnd);
}
// highlight newly active row
if (row > -1) {
emit dataChanged(rowBegin, rowEnd);
}
}
void MyModel::setActiveRow(int row)
{
if (active_row == row)
return; // no change
int oldRow = active_row;
active_row = row;
// de-highlight previously active row
if (oldRow > -1) {
QModelIndex rowBegin = index(oldRow, 0);
QModelIndex rowEnd = index(oldRow, columnCount() - 1);
emit dataChanged(rowBegin, rowEnd);
}
// highlight newly active row
if (row > -1) {
QModelIndex rowBegin = index(row, 0);
QModelIndex rowEnd = index(row, columnCount() - 1);
emit dataChanged(rowBegin, rowEnd);
}
}
To copy to clipboard, switch view to plain text mode
Cheers,
_
Bookmarks