0

I have a simple QComboBox but I cannot figure out how to change the text color of the selected item. It stays black but it should be white. I used the color:white; properties but it seems to affect only the color of the popup item list.

this is my current stylesheet:

background: rgb(61,61,61);
color: rgb(255,255,255);
selection-color: rgb(255, 255, 255);

the QComboBox keeps having this behaviour:

enter image description here

enter image description here

as you can see the selected item still has an unspecified black color.

Niklas
  • 13,005
  • 23
  • 79
  • 119
Gianluca Ghettini
  • 11,129
  • 19
  • 93
  • 159
  • 1
    Perhaps this will help: http://qt-project.org/forums/viewthread/5509 – TheDarkKnight Sep 08 '14 at 09:02
  • Is your combobox editable? How do you assign the stylesheet? – Ezee Sep 08 '14 at 09:20
  • no, it isn't editable. I've assigned the css using QtCreator (it's not applied using ->setStyleSheet() method) – Gianluca Ghettini Sep 08 '14 at 09:24
  • I see that other colors in your app are not standard too. Do you achieve it with CSS? Is it possible that your override the color somewhere? Try to create a new widget in QtCreator and set this stylesheet for it. Does it work? – Ezee Sep 08 '14 at 09:34
  • It might be possible that some parent element is overriding the standard color, I'll check it out... but isn't it possible to force a color on a child element even if some parent is overriding it? – Gianluca Ghettini Sep 08 '14 at 09:38
  • Yes, it's possible if another element has more elements in declaration hierarchy, for example, `QWidget:active` {} overrides `QComboBox` {}, `QWidget:active:hover` overrides both – Ezee Sep 08 '14 at 09:43
  • ok ,so in the case some parent element is overriding my text color how to enforce it at the child-level? – Gianluca Ghettini Sep 08 '14 at 10:05
  • The only way is to add more elements in the declaration of the GUI element: `QComboBox#name` or `ParentClass QComboBox#name` or even `ParentClass QComboBox#name:active` – Ezee Sep 08 '14 at 10:10

1 Answers1

1

I have solved this by including the padding property:

QComboBox { combobox-popup: 0; color: white; padding: 0px 0px 0px 0px; }

It seems setting the padding property (with any value) on the combobox in the style sheet makes it properly obey the colour styling.

See for reference: https://stackoverflow.com/a/24824810/4022402

Community
  • 1
  • 1
Grynium
  • 26
  • 6