Hi all !
I am trying to use QTableWidget to present some data with alternating row color. I used setAlternatingRowColors() and it worked fine, but now I want to use different alternating row colors for the column that the table is currently sorted by.
I gets ugly, because I can't find a way to get the order in which the rows are currently displayed!
The following method doesn't work in case we have several identical elements in a table:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
|
void casino::colorSortedColumn(int col) {
QColor color1 = QColor(192,200,202);
QColor color2 = QColor(226,238,234);
for (int i=0; i<ui->table->rowCount(); i++) {
QTableWidgetItem *it = ui->table->item(i, col);
if ( i % 2 == 0) it->setBackgroundColor(color1);
else it->setBackgroundColor(color2);
}
return;
}
|
Please, help me!
Thaaanks!