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. [Resolved] Dynamically change style of control from loaded QSS file
Forum Updated to NodeBB v4.3 + New Features

[Resolved] Dynamically change style of control from loaded QSS file

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.9k Views 1 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.
  • R Offline
    R Offline
    ronM71
    wrote on 30 Jan 2012, 15:57 last edited by
    #1

    In my application, the stylesheet for the entire application is taken from a resource file "default.qss" loaded into the application.

    I have two stylesheets defined there for a QListWidget:

    @QListWidget#Good{ ..some color properties }

    QListWidget#Bad { ..soem different color properties }@

    In a form, my QListWidget's Object name is "Good", so it adheres to the #good style. During runtime, I have a case where I want to "SetObjectName" it to "Bad" and have the style changed instantly in the UI.

    I have noticed two things:

    1. merely calling "SetObjectName("Bad");" doens't change the style from methods... 2) The only time "SetObjectName("Bad");" works is if called from the constructor of the Widget containing the QListWidget.

    Obviously i am missing some "update style" phase. Note that I cannot have "setStyleSheet" in code, it must come from the QSS file.

    What am I missing?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 30 Jan 2012, 16:12 last edited by
      #2

      The style will not update itself automatically when the value of the property changes. See "this FAQ":http://developer.qt.nokia.com/faq/answer/how_can_my_stylesheet_account_for_custom_properties.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ronM71
        wrote on 30 Jan 2012, 16:17 last edited by
        #3

        Yep:

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

        Did the job. Thanks!

        (Although, as having polish ancestry, I object to the wording of the API ;-) )

        1 Reply Last reply
        0

        1/3

        30 Jan 2012, 15:57

        • Login

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