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
Forum Updated to NodeBB v4.3 + New Features

Styled PushButton in checked state

Scheduled Pinned Locked Moved General and Desktop
push buttonstylesheet
6 Posts 2 Posters 2.8k Views 2 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.
  • A Offline
    A Offline
    Andy314
    wrote on 20 Jun 2015, 18:04 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 20 Jun 2015, 21:48 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
      • A Offline
        A Offline
        Andy314
        wrote on 21 Jun 2015, 15:25 last edited by
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 21 Jun 2015, 20:50 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

          A 1 Reply Last reply 22 Jun 2015, 16:27
          0
          • S SGaist
            21 Jun 2015, 20:50

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

            A Offline
            A Offline
            Andy314
            wrote on 22 Jun 2015, 16:27 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 22 Jun 2015, 22:35 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

              5/6

              22 Jun 2015, 16:27

              • Login

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