Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTreeWidgetItem find child by text

How to find item in QTreeWidgetItem by text? Is there an analog of QTreeWidget's findItem method ?

like image 720
Denis Avatar asked Apr 17 '15 08:04

Denis


1 Answers

I believe what you are looking for is recursive search in a QTreeWidget. For that you will have to use the combination of Qt::MatchContains | Qt::MatchRecursive as flag.

So if pMyTreeWidget is the pointer to your QTreeWidget and myText is the QString containing the text you want to search, assuming that the search has to be on column 0, the code will look something like:

QList<QTreeWidgetItem*> clist = pMyTreeWidget->findItems(myText, Qt::MatchContains|Qt::MatchRecursive, 0);
foreach(QTreeWidgetItem* item, clist)
{
    qDebug() << item->text(0);
}

If your requirement is to match the exact text, then you can use Qt::MatchExactly|Qt::MatchRecursive instead of Qt::MatchContains|Qt::MatchRecursive

like image 122
Nithish Avatar answered Oct 06 '22 09:10

Nithish