我正在尝试构建一个具有多个 QTreeWidgetItems 的 QTreeWidget,我尝试手动添加其中一些并且它可以工作。我的问题是如何使用 for 或 while 循环添加项目。
这是我的代码的一部分
Dwidget= new QDockWidget(this);
Dwidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
treeWidget= new QTreeWidget(Dwidget);
Titem= new QTreeWidgetItem(treeWidget);
Titem1= new QTreeWidgetItem();
Titem2= new QTreeWidgetItem();
Titem3= new QTreeWidgetItem();
Titem->setText(0,"WriterIdenSystem");
Titem->setIcon(0,*(new QIcon("D:/Users/200656336/Documents/Writer Identification/data_repository_icon.jpg")));
Titem1->setText(0,"Database for Writer Identification");
Titem1->setIcon(0,*(new QIcon("D:/Users/200656336/Documents/Writer Identification/card_file.png")));
Titem2->setText(0,"0001");
Titem2->setIcon(0,*(new QIcon("D:/Users/200656336/Documents/Writer Identification/Folder Open.png")));
Titem3->setText(0,"0002");
Titem3->setIcon(0,*(new QIcon("D:/Users/200656336/Documents/Writer Identification/Folder Open.png")));
Titem->addChild(Titem1);
Titem1->addChild(Titem2);
Titem1->addChild(Titem3);
treeWidget->addTopLevelItem(Titem);
connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), SLOT(on_actionRetrieve_Documents_triggered()));
Dwidget->setWidget(treeWidget);
addDockWidget(Qt::LeftDockWidgetArea,Dwidget);
Dwidget->show();
有任何想法吗??:)