how to hightlight certain rows in qt tablewidget?
Solved
General and Desktop
-
hello, everyone.
as showed in the above picture, now I want to hightlight certain lines in the table, meaning that after I click the down forward arrow in the scroll bar right in the picture, the hightlighted rows move up and when I click the up forward arrow in the scroll bar, the hightlighted rows shows again.
how to do that? Thank in advance! -
Hi
and this purple line should be something other than the currently
selected row ?
Like a color code on a row. ? -
Ok
so i assume you cannot just use the selection line for this.
(it can be set to select whole row at once)Well you can color the items backgrounds. that also work even if
the items are not currently shown. -
@mrjj ```
QTableWidgetItem *item1 = new QTableWidgetItem; item1->setTextColor(txtColor); item1->setBackgroundColor(backColor); item1->setTextAlignment(Qt::AlignCenter); ui->tableWidget->setItem(cnt,0,item1);
it is the code, following your advice, however, no effect.
-
@small_bird
Hi
Did you remember to adjust row/col count ?
Work fine hereui->tableWidget->setRowCount(5); ui->tableWidget->setColumnCount(5); for (int c = 0; c < ui->tableWidget->rowCount(); c++) { QTableWidgetItem *item1 = new QTableWidgetItem; item1->setTextColor(Qt::red); auto col = QColor( rand() % 255, rand() % 255, rand() % 255); item1->setBackgroundColor( col ); item1->setTextAlignment(Qt::AlignCenter); ui->tableWidget->setItem(c, 0, item1); }