Reputation: 1332
i want to style QComboBox through stylesheet so i applied following qss syntax.
QComboBox {
border: none;
border-radius: 0px;
background-color: rgb(255, 255, 255);
color: rgb(0, 0, 0);
selection-background-color: rgb(0, 85, 255);
font: 14pt;
}
QComboBox:editable {
background-color: rgb(255, 255, 255);
}
QComboBox:!editable:on, QComboBox::drop-down:editable:on {
background-color: rgb(200, 200, 200);
}
QComboBox:on { /* shift the text when the popup opens */
padding-top: 3px;
padding-left: 4px;
}
QComboBox::drop-down {
width: 0px;
height:0px;
border-radius: 0px;
}
QComboBox::drop-down:hover
{
border: none;
border-radius: 0px;
background-color: rgb(0, 170, 255);
}
QComboBox QAbstractItemView{
background-color: rgb(255, 255, 255);
border-radius: 0px;
color: rgb(0, 0, 0);
font: 14pt;
}
QComboBox QAbstractItemView:item{
color: rgb(85, 85, 0);
background-color: rgb(170, 170, 127);
selection-background-color: rgb(170, 170, 255);
selection-color: rgb(85, 0, 127);
height:40px;
font: 16pt;
}
problem: selection-background-color: rgb(170, 170, 255); in
QComboBox QAbstractItemView:item{
color: rgb(85, 85, 0);
background-color: rgb(170, 170, 127);
selection-background-color: rgb(170, 170, 255); <- Not Working
selection-color: rgb(85, 0, 127);
height:40px;
font: 16pt;
}
is not applying. drop down selected item background is not reflected. please help me to solve this problem.
Upvotes: 5
Views: 8484
Reputation: 21
I had this issue. Every time the combo box was selected (the item of focus in the GUI) the box would be blue with white text. I originally tried adding:
QComboBox QAbstractItemView {
selection-background-color: white;
}
However, this did not work.
After some investigating I realized that the "selection-background-color" tag was correct, but it wasn't on the correct object. Tagging "QComboBox QAbstractView" will change the drop down view, but not the QComboBox itself. To do this you have to attach the tag to the QComboBox (without limiting it to only the QAbstractItemView of the ComboBox). This is how I changed mine from blue to white (when selected):
QComboBox {
selection-background-color: white;
}
Upvotes: 2
Reputation: 11369
I just had the same issue, and for me none of the proposed solutions I found on the internet worked. What finally did it was this:
QComboBox::item:selected
{
background-color: rgb(170, 170, 255);
color: rgb(0, 0, 0);
}
Hoping this can help other users in search for this. Maybe this changed in recent versions (I'm using Qt 5.7).
Upvotes: 2
Reputation: 1373
Have you tried:
QComboBox QAbstractItemView
{
background-color: rgb(255, 255, 255);
selection-background-color: rgb(170, 170, 255); <- Should Now Work
border-radius: 0px;
color: rgb(0, 0, 0);
font: 14pt;
}
Upvotes: 7