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. How to force a style sheet recalculation
Forum Updated to NodeBB v4.3 + New Features

How to force a style sheet recalculation

Scheduled Pinned Locked Moved General and Desktop
24 Posts 11 Posters 28.9k Views 3 Watching
  • 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.
  • G Offline
    G Offline
    genjix
    wrote on last edited by
    #15

    wait, so there's no way to do style changes for hover/selecting a button? There should be :p

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #16

      genjix, for hovering or clicking on a button there are pseudo-states in stylesheets.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #17

        Just for reference:
        "http://developer.qt.nokia.com/faq/answer/how_can_my_stylesheet_account_for_custom_properties":http://developer.qt.nokia.com/faq/answer/how_can_my_stylesheet_account_for_custom_properties.

        Here it is indicated that using a unpolish()/polish() pair of calls would be the fastest way to force the update.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #18

          When first being classified as "a sensible idea" and asking for more info, the JIRA ticket has now been closed as "Out of scope" because Qt is "more focussed on QML than in widgets" now.

          I read in that: f*ck everybody who invested hundreds or thousands of developer hours into widget based applications; everybody who is not immediately jumping onto the immature Quick bandwagon is screwed.

          I am really disapointed by this. While I see Quick as a very interesting technology for creating flashy touch UI's, conventional widgets have a huge invested base and do have their advantages. At least it is proven technology. I would have expected to see them live on side by side for quite a while, as there are use cases for both stacks. It seems I was wrong. :-(

          1 Reply Last reply
          0
          • K Offline
            K Offline
            karolyi
            wrote on last edited by
            #19

            Coming here after googling, just a quick reply:

            meanwhile, QStyle.polish() seems to apply the recomputed style on the change widget.

            ODБOïO 1 Reply Last reply
            0
            • K karolyi

              Coming here after googling, just a quick reply:

              meanwhile, QStyle.polish() seems to apply the recomputed style on the change widget.

              ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by
              #20

              @karolyi said in How to force a style sheet recalculation:

              quick reply

              this topic is 8 years old

              1 Reply Last reply
              0
              • O ogoffart

                IIRC, calling buton->setStyleSheet("/* /"); should be enough to clear the caches for this widget and force a recomputation of the style.
                (Notice "/
                */" and not "" in order to avoid an empty stylesheet that would be ignored)

                W Offline
                W Offline
                WolfgangGriech
                wrote on last edited by
                #21

                @ogoffart you're my hero, I had discovered a weird effect on Qt6.9.1 (and later also on some older Qt6 versions), sending an empty or invalid string to setStyleSheet() didn't always clear the previously set stylesheet, but your proposed solution perfectly works, always! Thanks man!

                1 Reply Last reply
                1
                • L Offline
                  L Offline
                  larsmaxfield
                  wrote last edited by larsmaxfield
                  #22

                  The solution from @ogoffart works for me, too.

                  setStyleSheet() in >6.9.1 doesn't work for me to refresh the stylesheet. I use widget.setStyleSheet(widget.styleSheet()), but that isn't reliable. @WolfgangGriech also describes this.

                  Perhaps this should be reported as bug? It's been reported and fixed for 6.10.

                  JonBJ 1 Reply Last reply
                  0
                  • L larsmaxfield

                    The solution from @ogoffart works for me, too.

                    setStyleSheet() in >6.9.1 doesn't work for me to refresh the stylesheet. I use widget.setStyleSheet(widget.styleSheet()), but that isn't reliable. @WolfgangGriech also describes this.

                    Perhaps this should be reported as bug? It's been reported and fixed for 6.10.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote last edited by
                    #23

                    @larsmaxfield
                    FWIW, (I believe) I recall in some Qt 5 version years ago in order to get it reliably to count as a change I had to/ended up doing:

                    temp = widget.styleSheet();
                    widget.setStyleSheet("");
                    widget.setStyleSheet(temp);
                    
                    Pl45m4P 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @larsmaxfield
                      FWIW, (I believe) I recall in some Qt 5 version years ago in order to get it reliably to count as a change I had to/ended up doing:

                      temp = widget.styleSheet();
                      widget.setStyleSheet("");
                      widget.setStyleSheet(temp);
                      
                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote last edited by
                      #24

                      @JonB

                      Maybe even

                      • https://doc.qt.io/qt-6/qwidget.html#ensurePolished
                      • https://doc.qt.io/qt-6/qstyle.html#polish

                      That might force the style(sheet) to update too.
                      But usually the widget should do this when a new style(sheet) is applied.


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      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