我有一个项目QTreeWidget
,QTreeWidgetItem
但是只有根节点显示它的图标:
我一直在摸索什么可以关闭它,有什么提示吗?
ui->folderTree1->setUpdatesEnabled( false );
QTreeWidgetItem* treeRoot1 = new QTreeWidgetItem(ui->folderTree1);
treeRoot1->setIcon(0, QIcon(":/icons/black.png"));
treeRoot1->setText(0, tr("Root"));
treeRoot1->setExpanded(true);
addFoldersToTreeView(treeRoot1, ui->filePath1->text(), ui->filePath2->text());
ui->folderTree1->setUpdatesEnabled( true );
}
void MainWindow::addFoldersToTreeView(QTreeWidgetItem* currentWidget, QString leftPath, QString rightPath)
{
qDebug() << "MainWindow::addFoldersToTreeView" << leftPath;
QDir dir(leftPath);
QDir dir2(rightPath);
/* Add the folders */
foreach (QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
QString sImageName = ":/icons/black.png";
QTreeWidgetItem* newItem = new QTreeWidgetItem(currentWidget);
qDebug() << "MainWindow::addFoldersToTreeView.sImageName" << sImageName;
newItem->setIcon(0, QIcon(sImageName));
newItem->setText(0, subDir);
newItem->setExpanded(true);
newItem->setData(0, 1, QVariant(leftPath + QDir::separator() + subDir));
/* Recursively add sub-folders */
addFoldersToTreeView(newItem, leftPath + QDir::separator() + subDir, rightPath + QDir::separator() + subDir);
}