开发者

Why QTreeView does not show the data?

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(&paramList);

How to fix this?


in the header (private):

QStandardItemModel paramList;

in the .cpp

ui->treeView->setModel(&paramList);
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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜