Important: Please read the Qt Code of Conduct -

How to perform search in QTableWidget?

  • hi all,
    I want to perform a search operation in a table widget and want to highlight the row which contains particular word(key used for searching).
    Please somebody tell me is that possible?

  • You can use "QTableWidget::findItems() ":/doc/qt-4.8/qtablewidget.html#findItems to find the matching items and "QTableWidgetItem::setBackground() ":/doc/qt-4.8/qtablewidgetitem.html#setBackground to change the background color of the item.

  • Thank u Volker....
    I did like this...
    QList<QTableWidgetItem *> LTempTable =temp->findItems("001",Qt::MatchEndsWith);

    cout<<"the matched count:"<<LTempTable.count()<<endl;


    it was highlighting only that particular item, i want to highlight whole row,....please tell how to do that?

  • For each of the found items, also highlight the other cells on that row? It should be easy to find these other cells in the row, as the QTableWidgetItem rowPtr contains the row number you need to find the other items on the row.

  • ok thank u...:)

Log in to reply