Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to perform search in QTableWidget?
QtWS25 Last Chance

How to perform search in QTableWidget?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 14.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aurora
        wrote on last edited by
        #3

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

        cout<<"the matched count:"<<LTempTable.count()<<endl;
        foreach(rowPtr,LTempTable)
        {
        rowPtr->setBackground(Qt::red);
        }

        @

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aurora
            wrote on last edited by
            #5

            ok thank u...:)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved