qtreewidge怎么让树形控件默认展开状态

 我来答
匿名用户
2016-09-01
展开全部
oid WidgetTreeTEST::createDirectoryStruct()
{
QTreeWidgetItem *topLevelDirectory = new QTreeWidgetItem();
topLevelDirectory->setText(0, "DIR");
topLevelDirectory->setCheckState(0, Qt::Checked);
topLevelDirectory->setIcon(0, QIcon(":/Resources/folder.png"));

//Direcoty C
QTreeWidgetItem *directoryC = new QTreeWidgetItem();
directoryC->setText(0, "LocalDrive C");
directoryC->setCheckState(0, Qt::Checked);
directoryC->setIcon(0, QIcon(":/Resources/folder.png"));

QTreeWidgetItem *file1 = new QTreeWidgetItem();
file1->setText(0, "file1");
file1->setCheckState(0, Qt::Checked);
file1->setIcon(0, QIcon(":/Resources/file.png"));

QTreeWidgetItem *file2 = new QTreeWidgetItem();
file2->setText(0, "file2");
file2->setCheckState(0, Qt::Checked);
file2->setIcon(0, QIcon(":/Resources/file.png"));

directoryC->addChild(file1);
directoryC->addChild(file2);

//Directory D
QTreeWidgetItem *directoryD = new QTreeWidgetItem();
directoryD->setText(0, "LocalDrive D");
directoryD->setCheckState(0, Qt::Checked);
directoryD->setIcon(0, QIcon(":/Resources/folder.png"));

QTreeWidgetItem *file3 = new QTreeWidgetItem();
file3->setText(0, "file3");
file3->setCheckState(0, Qt::Checked);
file3->setIcon(0, QIcon(":/Resources/file.png"));

directoryD->addChild(file3);

//Direcoty E
QTreeWidgetItem *directoryE = new QTreeWidgetItem();
directoryE->setText(0, "LocalDrive E");
directoryE->setCheckState(0, Qt::Checked);
directoryE->setIcon(0, QIcon(":/Resources/folder.png"));

QTreeWidgetItem *file4 = new QTreeWidgetItem();
file4->setText(0, "file4");
file4->setCheckState(0, Qt::Checked);
file4->setIcon(0, QIcon(":/Resources/file.png"));

QTreeWidgetItem *file5 = new QTreeWidgetItem();
file5->setText(0, "file5");
file5->setCheckState(0, Qt::Checked);
file5->setIcon(0, QIcon(":/Resources/file.png"));

QTreeWidgetItem *d
匿名用户
2017-10-18
展开全部
treeWidget->expandAll();
若要始终保持展开状态,不能被收缩,再添加treeWidget->setItemsExpandable(false);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式