I want the new items to be inserted after the last row instead of first row.
for(i=0;i<10;i++)
{
QTreeWidgetItem* tempItem = new QTreeWidgetItem();
tempItem->setText(0,QString::number(i));
ui->treeWidget->insertTopLevelItem(tempItem,i);
}
It inserts the items at top, not at the bottom.
Try this way:
If you want to add a top level 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 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 order, they got added!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With