Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Widget does not apply stylesheet class
Forum Updated to NodeBB v4.3 + New Features

Widget does not apply stylesheet class

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 279 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dvassily
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • D Dvassily

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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 like widget["property" = "value"]) and you change the value of property in code you do need to unpolish/polish for Qt to correctly update widgets for the new dynamic value.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dvassily
        wrote on last edited by
        #3

        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. ;)

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved