QT样式表设置 之 QComboBox下拉框样式

£神魔★判官ぃ 2023-07-11 11:12 90阅读 0赞
  1. /* 未下拉时,QComboBox的样式 */
  2. QComboBox {
  3. border: 1px solid gray; /* 边框 */
  4. border-radius: 3px; /* 圆角 */
  5. padding: 1px 18px 1px 3px; /* 字体填衬 */
  6. color: #000;
  7. font: normal normal 15px "Microsoft YaHei";
  8. background: transparent;
  9. }
  10. /* 下拉后,整个下拉窗体样式 */
  11. QComboBox QAbstractItemView {
  12. outline: 0px solid gray; /* 选定项的虚框 */
  13. border: 1px solid yellow; /* 整个下拉窗体的边框 */
  14. color: green;
  15. background-color: red; /* 整个下拉窗体的背景色 */
  16. selection-background-color: lightgreen; /* 整个下拉窗体被选中项的背景色 */
  17. }
  18. /* 下拉后,整个下拉窗体每项的样式 */
  19. QComboBox QAbstractItemView::item {
  20. height: 50px; /* 项的高度(设置pComboBox->setView(new QListView());后,该项才起作用) */
  21. }
  22. /* 下拉后,整个下拉窗体越过每项的样式 */
  23. QComboBox QAbstractItemView::item:hover {
  24. color: #FFFFFF;
  25. background-color: lightgreen; /* 整个下拉窗体越过每项的背景色 */
  26. }
  27. /* 下拉后,整个下拉窗体被选择的每项的样式 */
  28. QComboBox QAbstractItemView::item:selected {
  29. color: #FFFFFF;
  30. background-color: lightgreen;
  31. }
  32. /* QComboBox中的垂直滚动条 */
  33. QComboBox QAbstractScrollArea QScrollBar:vertical {
  34. width: 10px;
  35. background-color: #d0d2d4; /* 空白区域的背景色 灰色green */
  36. }
  37. QComboBox QAbstractScrollArea QScrollBar::handle:vertical {
  38. border-radius: 5px; /* 圆角 */
  39. background: rgb(160,160,160); /* 小方块的背景色深灰lightblue */
  40. }
  41. QComboBox QAbstractScrollArea QScrollBar::handle:vertical:hover {
  42. background: rgb(90, 91, 93); /* 越过小方块的背景色yellow */
  43. }
  44. /* 设置为可编辑(setEditable(true))editable时,编辑区域的样式 */
  45. QComboBox:editable {
  46. background: green;
  47. }
  48. /* 设置为非编辑(setEditable(false))!editable时,整个QComboBox的样式 */
  49. QComboBox:!editable {
  50. background: blue;
  51. }
  52. /* 设置为可编辑editable时,点击整个QComboBox的样式 */
  53. QComboBox:editable:on {
  54. background: green;
  55. }
  56. /* 设置为非编辑!editable时,点击整个QComboBox的样式 */
  57. QComboBox:!editable:on {
  58. background: blue;
  59. }
  60. /* 设置为可编辑editable时,下拉框的样式 */
  61. QComboBox::drop-down:editable {
  62. background: lightblue;
  63. }
  64. /* 设置为可编辑editable时,点击下拉框的样式 */
  65. QComboBox::drop-down:editable:on {
  66. background: lightgreen;
  67. }
  68. /* 设置为非编辑!editable时,下拉框的样式 */
  69. QComboBox::drop-down:!editable {
  70. background: lightblue;
  71. }
  72. /* 设置为非编辑!editable时,点击下拉框的样式 */
  73. QComboBox::drop-down:!editable:on {
  74. background: lightgreen;
  75. }
  76. /* 点击QComboBox */
  77. QComboBox:on {
  78. }
  79. /* 下拉框样式 */
  80. QComboBox::drop-down {
  81. subcontrol-origin: padding; /* 子控件在父元素中的原点矩形。如果未指定此属性,则默认为padding。 */
  82. subcontrol-position: top right; /* 下拉框的位置(右上) */
  83. width: 15px; /* 下拉框的宽度 */
  84. border-left-width: 1px; /* 下拉框的左边界线宽度 */
  85. border-left-color: darkgray; /* 下拉框的左边界线颜色 */
  86. border-left-style: solid; /* 下拉框的左边界线为实线 */
  87. border-top-right-radius: 3px; /* 下拉框的右上边界线的圆角半径(应和整个QComboBox右上边界线的圆角半径一致) */
  88. border-bottom-right-radius: 3px; /* 同上 */
  89. }
  90.  /* 越过下拉框样式 */
  91.  QComboBox::drop-down:hover {
  92.    background: yellow;
  93.  }
  94. /* 下拉箭头样式 */ QComboBox::down-arrow { width: 15px; /* 下拉箭头的宽度(建议与下拉框drop-down的宽度一致) */ background: transparent; /* 下拉箭头的的背景色 */ padding: 0px 0px 0px 0px; /* 上内边距、右内边距、下内边距、左内边距 */ image: url(:/images/combobox_arrow_down.png); } /* 点击下拉箭头 */ QComboBox::down-arrow:on { image: url(:/images/combobox_arrow_up.png); /* 显示下拉箭头 */ }
  95. 注意:
  96. QComboBox* pComboBox = new QComboBox(this);
  97. pComboBox->setView(new QListView()); //下拉列表项高才能生效

转自https://www.cnblogs.com/tingtaishou/p/12155574.html

发表评论

表情:
评论列表 (有 0 条评论,90人围观)

还没有评论,来说两句吧...

相关阅读