PDA

View Full Version : Style Sheets: Change font-style in QComboBox but not in corresponding popup



Daniel adB
24th September 2014, 17:48
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:



QComboBox#librarySettingsBox QListView {
font-style: normal;
/* background-color: rgb(255, 255, 127);*/
}
QComboBox[dirty="true"] {
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:



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?

Rajesh.Rathod
25th September 2014, 14:07
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/stylesheet-reference.html#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; }

Daniel adB
29th September 2014, 14:21
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.



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.

Rajesh.Rathod
1st October 2014, 06:29
Qt 5.1.0 & Qt Creator 2.7.2.