How to highlight a row in a QTableWidget?

I have a QTableWidget with 9000 data. I can search data from a table, for example, if I search for "10", whole data starting with "10" will be displayed. Now I need to select the first line, as it shows the exact search result.

I use:

 ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); 

to highlight the selected line.

How can I highlight the first row of a table?

+6
source share
1 answer

I'm not sure I don’t understand why you need to set the selection behavior if you are not planning so that the user can make a selection by clicking on the cells. And if you want this to be the default behavior, just set this as the tableWidget property when you use QT designer .

But you can certainly:

 ui->tableWidget->selectRow(0); 

This will highlight the line.

+6
source

Source: https://habr.com/ru/post/904529/


All Articles