QT QTreewidget节点打开关闭状态图标

时间:2021-12-25 09:57:33

QT QTreewidget节点打开关闭状态图标

QTreeWidgetItem *root = new QTreeWidgetItem(ui.treeWidget, QStringList(fileName)); 
root->setIcon(0, QIcon("./Resources/RsProduct16.gif"));   

QIcon icon; 
icon.addPixmap(QPixmap("./Resources/RsGroupOpen16.gif"), QIcon::Normal, QIcon::On);//节点打开状态 
icon.addPixmap(QPixmap("./Resources/RsGroupClosed16.gif"), QIcon::Normal, QIcon::Off);//节点关闭状态   

//metadata 
QTreeWidgetItem *leafMetadata = new QTreeWidgetItem(root, QStringList(QString(tr("Metadata")))); 
leafMetadata->setIcon(0, icon);
root->addChild(leafMetadata); //bands QTreeWidgetItem *leaf2 = new QTreeWidgetItem(root, QStringList(QString(tr("Bands")))); leaf2->setIcon(0, icon); root->addChild(leaf2);