[ACCEPTED]-If I add an item to QTreeWidget it always gets inserted in first row-qt
Accepted answer
Try this way:
If you want to add a top level 3 item with children:
//you could also create it dinamically
QTreeWidget * tree = ui->treeWidget;
QTreeWidgetItem * topLevel = new QTreeWidgetItem();
topLevel->setText(0, "This is top level");
for(int i=0; i<5; i++)
{
QTreeWidgetItem * item = new QTreeWidgetItem();
item->setText(0,"item " + QString::number(i+1));
topLevel->addChild(item);
}
tree->addTopLevelItem(topLevel);
Or if you want to add 2 more top-levels:
for(int i=0; i<5; i++)
{
QTreeWidgetItem * item = new QTreeWidgetItem();
item->setText(0,"top-level " + QString::number(i+1));
tree->addTopLevelItem(item);
}
Note, that they are in the 1 order, they got added!
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.