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
{
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);
若要始终保持展开状态,不能被收缩,再添加treeWidget->setItemsExpandable(false);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询