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. Styled PushButton in checked state
QtWS25 Last Chance

Styled PushButton in checked state

Scheduled Pinned Locked Moved General and Desktop
push buttonstylesheet
6 Posts 2 Posters 2.7k 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.
  • Andy314A Online
    Andy314A Online
    Andy314
    wrote on last edited by Andy314
    #1

    Hello !
    I want a pushbutton with a green background in checked state and tried this style for the button:
    checked {background-color: green ; border: none;}
    This style has no effect!

    What I am doing wrong?

    PS: I use Windows 8.1

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QPushButton:checked {background-color: green; border: none;}

      will do what you want

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Andy314A Online
        Andy314A Online
        Andy314
        wrote on last edited by
        #3

        Works!
        Thank you, I thought the property of the QPushButton has the local context QPushButton.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You were missing the : before checked so
          ":checked {background-color: green ; border: none;}"
          will also work

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Andy314A 1 Reply Last reply
          0
          • SGaistS SGaist

            You were missing the : before checked so
            ":checked {background-color: green ; border: none;}"
            will also work

            Andy314A Online
            Andy314A Online
            Andy314
            wrote on last edited by
            #5

            Hello @SGaist !
            :checked {background-color: lightgreen; border: 1px solid;}
            QPushButton {background-color: red; border: 1px solid; padding: 6px}
            works.

            but how I can avoid the second type name ?
            (I need this style for different widgedts)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              AFAIK, you can't, however you can still re-use it by using something like:

              QString styleSheet("%1:checked {background-color: lightgreen; border: 1px solid;} "
              "%1 {background-color: red; border: 1px solid; padding: 6px}");
              
              myWidget->setStyleSheet(styleSheet.arg(myWidget->metaObject()->className()));
              

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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