PDA

View Full Version : findItems not working with tree



mstegehu
12th August 2009, 16:09
Hello,

I have created a QTreeWidget with several columns. In the first column I create a tree of QTreeWidgetItems.

When I use the function findItems on a other column it never returns an list with items for a item that is not the root in the first column.

So basically it will only find QTreeWidgetItems when the parent is the TreeWidget.

Am I using this functionallity wrong? I expect to get the other items to regardless of their tree depth?

Regards,

Marcel

wysota
12th August 2009, 19:06
Please provide a minimal compilable example reproducing the problem.

mstegehu
17th August 2009, 07:20
In de example below only 1 will be printed.

const indexColumn (1);

// Create TreeWidget
{
QTreeWidget treeView = new QTreeWidget(parent);
QTreeWidgetItem *___qtreewidgetitem = listviewSummary->headerItem();
___qtreewidgetitem->setText(0, QApplication::translate("Name", "Id", 0, QApplication::UnicodeUTF8));
___qtreewidgetitem->setText(1, QApplication::translate("Name", "TestName", 0, QApplication::UnicodeUTF8));
}

// Fill TreeWidget with one tree
{
TreeWidgetItem item1 = new TreeWidgetItem (treeView);
item1.setText (indexColumn, QString("1"));
TreeWidgetItem item2 = new TreeWidgetItem (item1);
item2.setText (indexColumn, QString("2"));
TreeWidgetItem item3 = new TreeWidgetItem (item2);
item3.setText (indexColumn, QString("3"));
}

// Loop TreeWidget
{
for (int index (0) ; index < 5 ; ++index)
{
// Bug in QT (187598 & 88548)
// Because column not equals 0 all childItems are not found. Root item is found.
QList<QTreeWidgetItem *> treeWidgetItemList (findItems ( QString ("%1").arg (index), Qt::MatchContains, indexColumn));

if (!treeWidgetItemList.isEmpty ())
{
qWarning ("Index: %d", treeWidgetItemList.first ().text (indexColumn));
}
}
}

Existing bugs already mentioned in QT bugtracker:

http://qt.nokia.com/developer/task-tracker/index_html?method=entry&id=85548

http://qt.nokia.com/developer/task-tracker/index_html?method=entry&id=187598