1. QComboBox {
  2. border: 1px solid #bebebe;
  3. padding: 1px 18px 1px 3px;
  4. font: normal normal 16px "Microsoft YaHei";
  5. color: #555555;
  6. background: transparent;
  7. }
  8. QComboBox:editable{
  9. background: transparent;
  10. }
  11. QComboBox:!editable, QComboBox::drop-down:editable{
  12. background: transparent;
  13. }
  14. QComboBox:!editable:on, QComboBox::drop-down:editable:on{
  15. background: transparent;
  16. }
  17. QComboBox:!on{
  18. }
  19. QComboBox:on{ /* the popup opens */
  20. color: #555555;
  21. border-color: #327cc0;
  22. background: transparent;
  23. }
  24. QComboBox::drop-down{
  25. subcontrol-origin: padding;
  26. subcontrol-position: top right;
  27. width: 20px;
  28. border-left-width: 1px;
  29. border-left-color: darkgray;
  30. }
  31. QComboBox::down-arrow {
  32. image: url(:/common/combobox_arrow);
  33. }
  34. QComboBox::down-arrow:on {
  35. image: url(:/common/combobox_arrow_up);
  36. }
  37. QComboBox QAbstractItemView {
  38. outline: 0;
  39. border: 1px solid #327cc0;
  40. background-color: #F1F3F3;
  41. font: normal normal 14px "Microsoft YaHei";
  42. }
  43. QComboBox QAbstractItemView::item {
  44. height: 32px;
  45. color: #555555;
  46. background-color: transparent;
  47. }
  48. QComboBox QAbstractItemView::item:hover {
  49. color: #FFFFFF;
  50. background-color: #327cc0;
  51. }
  52. QComboBox QAbstractItemView::item:selected {
  53. color: #FFFFFF;
  54. background-color: #327cc0;
  55. }
  56. QComboBox QAbstractScrollArea QScrollBar:vertical {
  57. background-color: #d0d2d4;
  58. }
  59. QComboBox QAbstractScrollArea QScrollBar::handle:vertical {
  60. background: rgb(160,160,160);
  61. }
  62. QComboBox QAbstractScrollArea QScrollBar::handle:vertical:hover {
  63. background: rgb(90, 91, 93);
  64. }

使用需要注意的点

  1. QCombox *box = new QComboBox();
  2. // 只有调用了setView(new QListView()), qss才能生效, 这是Qt的一个bug
  3. box->setView(new QListView());

效果

效果.gif