大家好。我目前正在做QTreeView,通過自定義Style Sheets自定義外觀,想要區分根節點和葉子節點。但是在Style Sheets中沒有找到相應的方法。我看了一下Qt的屬性選擇器可能是突破口,但是還沒有思路。
現在達到這樣的效果了:

如果能夠區分根節點和葉子節點,那么我就可以將根節點的圖片換成不帶連接點的+號了。
QSS代碼如下:
QTreeView::branch:has-siblings:!adjoins-item {
margin-left: 6px;
border-image: url(:/branch-vline.png);
}
QTreeView::branch:!has-children:has-siblings:adjoins-item {
image: url(:/branch-more.svg);
margin-left: -45px;
background-image: url(:/branch-single.svg);
background-position: right;
background-repeat: no-repeat;
}
QTreeView::branch:!has-children:!has-siblings:adjoins-item {
border-image: none;
image: url(:/branch-end.svg);
margin-left: -45px;
background-image: url(:/branch-single.svg);
background-position: right;
background-repeat: no-repeat;
}
QTreeView::branch:has-children:adjoins-item:open {
border-image: none;
image: url(:/branch-more.svg);
margin-left: -45px;
background-image: url(:/branch-open.svg);
background-position: right;
background-repeat: no-repeat;
}
QTreeView::branch:has-children:adjoins-item:closed {
border-image: none;
image: url(:/branch-more.svg);
margin-left: -45px;
background-image: url(:/branch-closed.svg);
background-position: right;
background-repeat: no-repeat;
}
QTreeView::branch:has-children:adjoins-item:open:first {
background-image: url(:/branch-root-open.svg);
}
QTreeView::branch:has-children:adjoins-item:closed:first {
background-image: url(:/branch-root-closed.svg);
}
uj5u.com熱心網友回復:
https://blog.csdn.net/liang19890820/article/details/52606662轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/128027.html
標籤:Qt
