Style Sheets: Change font-style in QComboBox but not in corresponding popup
Depending on some dynamic property, I'd like to set the font style in the top-item of a QComboBox to italic, but keep the appearance of the items in the corresponding popup (QListView).
I tried it with the following qss:
Code:
font-style: normal;
/* background-color: rgb(255, 255, 127);*/
}
font-style: italic;
/* background-color: rgb(85, 0, 255);*/
}
In my C++ code, I call update on the widget after setting the property like this:
Code:
ui->librarySettingsBox->setProperty("dirty", dirty);
ui->librarySettingsBox->style()->unpolish(ui->librarySettingsBox);
ui->librarySettingsBox->style()->polish(ui->librarySettingsBox);
ui->librarySettingsBox->update();
The "font-style: normal" setting is supposed to override the italic setting in the QListView, as it has a higher priority due to the id-tag contained. This can also be confirmed by uncommenting the "background-color" tags. However, the font-style does not seem to have any effect on the QListView. Why is it so and how can I fix it?
Re: Style Sheets: Change font-style in QComboBox but not in corresponding popup
QComboBox has two different parts the edit box is actually QLineEdit and then PopUp which is I think QListView(Please check this).
Try to set different stylesheet for both the component for given QComboBox and it should work.
see below link which gives list of state of any qt control for stylesheet...
http://qt-project.org/doc/qt-4.8/sty...ml#paletterole
I have tried one example in which combobox font is italics and dropdown font is normal, below is stylesheet used for that...
QComboBox {font-style: italic;}
QComboBox QListView { font-style: normal; }
Re: Style Sheets: Change font-style in QComboBox but not in corresponding popup
Unfortunately, this doesn't work. The problem doesn't seem to be with the selectors, but with applying a font-style to the QListView, as overriding styles in the QListView does work e.g. for background-colors.
Quote:
Originally Posted by
Rajesh.Rathod
I have tried one example in which combobox font is italics and dropdown font is normal, below is stylesheet used for that...
QComboBox {font-style: italic;}
QComboBox QListView { font-style: normal; }
Which Version of Qt did you use for that? Maybe I should say I'm using Qt 5.2.1.
Re: Style Sheets: Change font-style in QComboBox but not in corresponding popup
Qt 5.1.0 & Qt Creator 2.7.2.