search and highlight the items in a qtablewidget

2.6k Views Asked by At

I'm using Python and PyQt and I have created a QTableWidget which I populate with data. Is there a way to search for a specific value and if the program finds something, can it hightlight the rows ?

1

There are 1 best solutions below

0
On

Use list-of-QTableWidgetItem QTableWidget.findItems (self, QString text, Qt.MatchFlags flags) to find your specific items.

http://pyqt.sourceforge.net/Docs/PyQt4/qtablewidget.html#findItems

After this iterate throw this list and use QTableWidgetItem.setBackgroundColor (self, QColor color) for example to highlight this item

http://pyqt.sourceforge.net/Docs/PyQt4/qtablewidgetitem.html#setBackgroundColor

To highlight whole row you can use setBackgroundColor for every item in the table(with given row) or if you want to select rows, you can use this or just selectRow()

http://pyqt.sourceforge.net/Docs/PyQt4/qtableview.html#selectRow