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. style sheet and colors that change dynamically when a field is enabled or disabled

style sheet and colors that change dynamically when a field is enabled or disabled

Scheduled Pinned Locked Moved Solved General and Desktop
guistylesheetwidgets
3 Posts 3 Posters 7.2k 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.
  • gautieryG Offline
    gautieryG Offline
    gautiery
    wrote on last edited by
    #1

    Hi

    I am trying to change the colors for certain widgets. For the "enabled" state, the widget will be blue and for the "disabled" state they will be in color that is between blue and gray.
    My code looks like this :

    qwidget->setStyleSheet(
                    "QWidget[enabled=\"false\"] {color: #64B2D1;}"
                    "QWidget{color: blue;}");
    

    It works fine initially but for instance, when a disabled widget is enabled, the color does not change and stays grayish.
    What should I do to make this color effect dynamic.

    Thanks

    the_T 1 Reply Last reply
    0
    • gautieryG gautiery

      Hi

      I am trying to change the colors for certain widgets. For the "enabled" state, the widget will be blue and for the "disabled" state they will be in color that is between blue and gray.
      My code looks like this :

      qwidget->setStyleSheet(
                      "QWidget[enabled=\"false\"] {color: #64B2D1;}"
                      "QWidget{color: blue;}");
      

      It works fine initially but for instance, when a disabled widget is enabled, the color does not change and stays grayish.
      What should I do to make this color effect dynamic.

      Thanks

      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      @gautiery

      After changing a property you have to update the style() of your widget

      see https://wiki.qt.io/Dynamic_Properties_and_Stylesheets

      -- No support in PM --

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        if instead of checking the property you use the pseudo-state it should work

        qwidget->setStyleSheet(
        "QWidget:disabled{color: #64B2D1;}"
        "QWidget{color: blue;}");
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2

        • Login

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