QTreeWidgetItem和QTreeWidgetItemIterator

本文介绍了一个使用Qt的树形控件(treeWidget)进行界面设计的示例,展示了如何设置树形控件的隐藏头部、清空内容、添加自定义项,并通过迭代器遍历所有项来获取子项的类型和状态。此教程适用于希望了解Qt中树形控件详细操作的开发者。
摘要由CSDN通过智能技术生成

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;
}

转载于:https://www.cnblogs.com/ShiShouTHS/p/11083349.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值