开发者

Why QTreeView does not show the data?

开发者 https://www.devze.com 2023-01-29 10:49 出处:网络
I have a trouble with QTreeView. When I run this code ui->treeView does not show the data: QStandardItemModel paramList;

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

精彩评论

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