item的样式

  1. /*鼠标悬浮*/
  2. QTreeView::item:hover {
  3. background: green;
  4. border: 1px solid red;
  5. }
  6. /*鼠标点击(选择)*/
  7. QTreeView::item:selected {
  8. border: 1px solid orange;
  9. }
  10. QTreeView::item:selected:active {
  11. background: skyblue;
  12. }
  13. QTreeView::item:selected:!active {
  14. background: blue;
  15. }

image.png

分支的样式-用颜色表示

  1. /*节点用颜色表示*/
  2. QTreeView::branch {
  3. background: palette(base);
  4. }
  5. /*节点展开 有兄弟节点, 但没有相邻项*/
  6. QTreeView::branch:has-siblings:!adjoins-item {
  7. background: cyan;
  8. }
  9. /*相邻项且有兄弟节点,即不是该层级的最后一个节点*/
  10. QTreeView::branch:has-siblings:adjoins-item {
  11. background: red;
  12. }
  13. /*不是相邻项, 没有孩子节点, 没有兄弟节点*/
  14. QTreeView::branch:!has-children:!has-siblings:adjoins-item {
  15. background: blue;
  16. }
  17. /*有兄弟节点 又有孩子节点,节点未展开*/
  18. QTreeView::branch:closed:has-children:has-siblings {
  19. background: pink;
  20. }
  21. /*有兄弟节点 又有孩子节点,节点展开*/
  22. QTreeView::branch:open:has-children:has-siblings {
  23. background: magenta;
  24. }
  25. /*没有有兄弟节点 但有孩子节点,节点未展开*/
  26. QTreeView::branch:has-children:!has-siblings:closed {
  27. background: gray;
  28. }
  29. /*没有有兄弟节点 但有孩子节点,节点展开*/
  30. QTreeView::branch:open:has-children:!has-siblings {
  31. background: green;
  32. }

image.png

分支的样式-用图片表示

  1. /*有兄弟节点,但没有相邻项*/
  2. QTreeView::branch:has-siblings:!adjoins-item {
  3. border-image: url(branch-vline.png) 0;
  4. }
  5. /*有相邻项, 有兄弟节点*/
  6. QTreeView::branch:has-siblings:adjoins-item {
  7. border-image: url(branch-more.png) 0;
  8. }
  9. /*该层级节点的最后一个节点*/
  10. QTreeView::branch:!has-children:!has-siblings:adjoins-item {
  11. border-image: url(branch-end.png) 0;
  12. }
  13. /* 节点关闭*/
  14. QTreeView::branch:has-children:!has-siblings:closed,
  15. QTreeView::branch:closed:has-children:has-siblings {
  16. border-image: none;
  17. image: url(branch-closed.png);
  18. }
  19. /* 节点展开*/
  20. QTreeView::branch:open:has-children:!has-siblings,
  21. QTreeView::branch:open:has-children:has-siblings {
  22. border-image: none;
  23. image: url(branch-open.png);
  24. }

image.png
使用的图片:
branch-closed.png
branch-closed.png
branch-open.png
branch-open.png

branch-vline.png
branch-vline.png
branch-more.png
branch-more.png
branch-end.png
branch-end.png