1、{
ui->treeWidget->setHeaderHidden(true); ui->treeWidget->clear(); QTreeWidgetItem *imageItem1 = new QTreeWidgetItem(ui->treeWidget, QStringList(QString("程序"))); imageItem1->setIcon(0, QIcon("picture/ProgramIcon/ParentFile.png")); AddQTreeWidgetItemChild(imageItem1, "指令程序", QIcon("picture/ProgramIcon/File.png"), 1)->setCheckState(0, Qt::Unchecked);QTreeWidgetItem *imageItem2 = new QTreeWidgetItem(ui->treeWidget, QStringList(QString("参数")));
imageItem2->setIcon(0, QIcon("picture/ProgramIcon/ParentFile.png")); AddQTreeWidgetItemChild(imageItem2, "PLC/网络/远程口令", QIcon("picture/ProgramIcon/File.png"), 2)->setCheckState(0, Qt::Unchecked);QTreeWidgetItem *imageItem3 = new QTreeWidgetItem(ui->treeWidget, QStringList(QString("软元件内容")));
imageItem3->setIcon(0, QIcon("picture/ProgramIcon/ParentFile.png")); AddQTreeWidgetItemChild(imageItem3, "软元件数据", QIcon("picture/ProgramIcon/File.png"), 3)->setCheckState(0, Qt::Unchecked);//connect(ui->treeWidget, SIGNAL(itemPressed(QTreeWidgetItem*, int)), this, SLOT(slotItemPressed(QTreeWidgetItem*, int)));
ui->treeWidget->expandAll(); }2、
QTreeWidgetItemIterator it(ui->treeWidget);
while (*it) { if ((*it)->childCount() > 0) { for (int i = 0; i < (*it)->childCount(); i++) { int iType = (*it)->child(i)->type(); switch (iType) { case 0:break;
case 1: m_bPrg = (*it)->child(i)->checkState(0); break; case 2: m_bParam = (*it)->child(i)->checkState(0); break; case 3: m_bSoftElem = (*it)->child(i)->checkState(0); break; } } } ++it; }