Are Qt's stylesheets really handling _dynamic_ properties?

后端 未结 4 379
名媛妹妹
名媛妹妹 2021-01-04 01:47

Is Qt\'s dynamic properties really so dynamic with stylesheets?

I have the basic example from stylesheets and dynamic properties:

/*stylesheet:*/
*[f         


        
相关标签:
4条回答
  • 2021-01-04 02:01

    I tried this too with no luck, and when I found the following text in the documentation, I gave up. See The Style Sheet Syntax:

    Warning: If the value of the Qt property changes after the style sheet has been set, it might be necessary to force a style sheet recomputation. One way to achieve this is to unset the style sheet and set it again.

    0 讨论(0)
  • 2021-01-04 02:04

    The following works for me to ensure a proper restyling of the widget:

    myWidget->setStyle(QApplication::style())

    Forcing a recomputation of the stylesheets as proposed by mdcl did not work for me. I am using Qt 4.5.3.

    0 讨论(0)
  • 2021-01-04 02:20

    Qt has the following recommendation in their FAQ:

    style()->unpolish(theWidget);
    style()->polish(theWidget);
    

    They also say you can reset the stylesheet by doing the following but it is more expensive:

    setStyleSheet(styleSheet());
    
    0 讨论(0)
  • 2021-01-04 02:22

    I found a quick, although a bit hackish, way to update widget's styling.

    myWidget->style()->unpolish(myWidget);
    myWidget->ensurePolished();
    

    Doing this after changing properties keeps correlation between property data and UI.

    0 讨论(0)
提交回复
热议问题