跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  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

已排程 已置頂 已鎖定 已移動 General and Desktop
24 貼文 11 Posters 28.8k 瀏覽 3 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • 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 離線
    W 離線
    WolfgangGriech
    寫於 最後由 編輯
    #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 條回覆 最後回覆
    1
    • L 離線
      L 離線
      larsmaxfield
      編寫 最後由 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 條回覆 最後回覆
      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 線上
        JonBJ 線上
        JonB
        編寫 最後由 編輯
        #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 條回覆 最後回覆
        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 離線
          Pl45m4P 離線
          Pl45m4
          編寫 最後由 編輯
          #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 條回覆 最後回覆
          1

          • 登入

          • Login or register to search.
          • 第一個貼文
            最後的貼文
          0
          • 版面
          • 最新
          • 標籤
          • 熱門
          • 使用者
          • 群組
          • 搜尋
          • Get Qt Extensions
          • Unsolved