Question

I have vector with 6 numbers, which I want insert to list and add this list to QTreeWidget. First number of list is on "root" level and other numbers are sublevel "root".

I don't know how to do it.

Image with describe: enter image description here

Code:

void modal::zapis() {
ui->listWidget->clear();
ui->treeWidget->clear();
QList<QTreeWidgetItem *> items;

for(int i=0;i<v.size();i++)
{
    QString string;
    string.setNum(v.at(i));
    ui->listWidget->addItem(string);
    QTreeWidgetItem *root = new QTreeWidgetItem(ui->treeWidget);
    if(i==0)
    {
        root->setText(0, string);
    }
    else
    {
        QTreeWidgetItem *item = new QTreeWidgetItem(root);
        item->setText(0, string);
    }
}
}

Thank you for any ideas.

Was it helpful?

Solution

You are creating a new root node on every iteration, it just needs creating once per call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top