QTreeWidget隐藏去掉或更改item项前的展开折叠三角图标

//如果不想要展开折叠图标(三角图标),可以用以下代码
{
//隐藏根节点项前的图标(展开折叠图标)
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

 

你可能感兴趣的:(QTreeWidget隐藏去掉或更改item项前的展开折叠三角图标)