I have a trouble with QTreeView. When I run this code ui->treeView
does not show the data:
QStandardItemModel paramList;
QStandardItem itemroot("cats");
QStan开发者_如何学PythondardItem item1("cats");
QStandardItem item2("dogs");
QStandardItem item3("rats");
itemroot.setChild(0,&item1);
itemroot.setChild(1,&item2);
itemroot.setChild(2,&item3);
paramList.setItem(0,&itemroot);
ui->treeView->setModel(¶mList);
How to fix this?
in the header (private):
QStandardItemModel paramList;
in the .cpp
ui->treeView->setModel(¶mList);
QStandardItem *itemroot = new QStandardItem("cats");
QStandardItem *item1 = new QStandardItem("cats");
QStandardItem *item2 = new QStandardItem("dogs");
QStandardItem *item3 = new QStandardItem("rats");
itemroot->setChild(0,item1);
itemroot->setChild(1,item2);
itemroot->setChild(2,item3);
paramList.setItem(0,itemroot);
精彩评论