//如果不想要展開折疊圖標(三角圖標),可以用以下代碼
{
//隱藏根節點項前的圖標(展開折疊圖標)
ui.treeWidget->setRootIsDecorated(false);
//如果只是隱藏根點的展開折疊圖標而子節點保留,則只需要上面語句
ui.treeWidget->setStyleSheet("QTreeView::branch:has-children:!has-siblings:closed,\
QTreeView::branch:closed:has-children:has-siblings{border-image: none; image: none;}\
QTreeView::branch:open:has-children:!has-siblings,\
QTreeView::branch:open:has-children:has-siblings{border-image: none; image: none;}");
}
//如果想把展開折疊圖標(三角圖標)換成自己的圖標,可以用以下代碼
{
ui.treeWidget->setStyleSheet("QTreeView::branch:has-children:!has-siblings:closed,\
QTreeView::branch:closed:has-children:has-siblings{border-image: none; image: url(:/QtXmlTest/Resources/image/plus.png);}\
QTreeView::branch:open:has-children:!has-siblings,\
QTreeView::branch:open:has-children:has-siblings{border-image: none; image: url(:/QtXmlTest/Resources/image/minus.png);}");
}
//把plus.png和minus.png改為自己的圖片就可以了
一份完整的QTreeWidget示例,下載地址:http://download.csdn.net/download/jxbinwd/10044343
