Solved Widget does not apply stylesheet class
-
Hello !
I would like to get some explanations about the following problem : I have a QMainWindow in which a QDialog is opened following to an user click. In the QDialog, there is a QFrame (applicationFrame) on which i added the dynamic property class=bordered-frame so as to draw a rounded border surrounding the frame.
I use the same class in other parts of the QMainWindow and it works well. The problem is that the QFrame applicationFrame does not apply the class to itself. I managed to make it work by adding the following statements :ui.applicationFrame->style()->unpolish(ui.applicationFrame); ui.applicationFrame->style()->polish(ui.applicationFrame);
However, it seems to me that it should work without with two statements. Could you provide me some explanations?
Thanks you in advance.
Dvassily
-
@Dvassily
You do not explain just what you do for "added the dynamic property class=bordered-frame". As a general statement, if you reassign a stylesheet on a widget (setStylesheet()
) you should not have to unpolish/polish, but if you set something dynamic ( you have a rule likewidget["property" = "value"]
) and you change the value ofproperty
in code you do need to unpolish/polish for Qt to correctly update widgets for the new dynamic value. -
I just solved your problem thanks to your post. When i said "added the dynamic property class=bordered-frame" i wanted to say "added a dynamic property of key 'class' and value 'bordered-frame' on the QFrame with the help of Qt designer. The problem is that i left the translatable checkbox checked, so code generated by uic was :
applicationFrame->setProperty("class", QVariant(QCoreApplication::translate("SettingsWindow", "bordered-frame", nullptr)));
When i unchecked the translatable checkbox, the generated code became :
applicationFrame->setProperty("class", QVariant(QString::fromUtf8("bordered-frame")));
And consequently, it works well withtout unpolish/polish. Probably because the stylesheet is applied after the dynamic property is set.
Thanks your for your help. ;)