[SOLVED]How to read the items in QTreeWidget
-
Hi everyone I am new to use QTreeWidget
I can add, remove the items to QTreeWidget.I added the items like
India-->Delhi,AndhraPradesh,TamilNadu
USA-->Alaska,California,GeorgiaFor reading the items I wrote a code like this
@ QTreeWidgetItemIterator it(ui->treeWidget);
while (*it) {
ui->textEdit->append((*it)->text(0));
++it;
}@Which gives the output like this...
India
Delhi
AndhraPradesh
TamilNadu
USA
Alaska
California
GeorgiaBut my requirement is I want the country names in one QTextEdit and the States in other QTextEdit.
How can we know that any item is having any children?
Thank you. -
Hi, I solved this problem by the following code.
@void TreeTest::itemDoubleClicked(QTreeWidgetItem item, int column)
{
QList <QTreeWidgetItem>List;
if(item->childCount()>0)
{
List = item->takeChildren();
addToParentList(item,column);
for(int idx=0; idx<List.length(); idx++)
addToChildList(List.at(idx),column);} else addToParentList(item,column); delete item;
}
void TreeTest::addToParentList(QTreeWidgetItem *item, int column)
{
ui->textEdit->append(item->text(column));
}
void TreeTest::addToChildList(QTreeWidgetItem *item, int column)
{
ui->textEdit_1->append(item->text(column));
}
@Thank you.