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. How to correctly set push button style when pressed?
Forum Updated to NodeBB v4.3 + New Features

How to correctly set push button style when pressed?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 7.8k 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.
  • T Offline
    T Offline
    testevpsa
    wrote on last edited by
    #1

    Hello, I'm new to Qt and I'm using Qt Designer.

    My Problem is:
    I'm unable to set a style to a push button when it is pressed. See the image below:
    0_1529944422963_0d03a4c0-4f20-470c-89c6-9c39fcbd4513-image.png

    The stylesheet pressed state has no effect on the button, does anyone see what I am doing wrong?

    Thank you for your time, have a good day!

    Gojir4G 1 Reply Last reply
    0
    • T testevpsa

      Hello, I'm new to Qt and I'm using Qt Designer.

      My Problem is:
      I'm unable to set a style to a push button when it is pressed. See the image below:
      0_1529944422963_0d03a4c0-4f20-470c-89c6-9c39fcbd4513-image.png

      The stylesheet pressed state has no effect on the button, does anyone see what I am doing wrong?

      Thank you for your time, have a good day!

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @testevpsa Hi,

      Maybe your first 4 lines overrides the other definitions because they are global. Try to enclose them in QPushButton{...}

      QPushButton {
          background-color: rgb(51, 153, 204);
          ...
      }
      QPushButton:pressed {
          background-color: rgb(224, 0, 0);
          ...
      }
      
      T A 2 Replies Last reply
      2
      • Gojir4G Gojir4

        @testevpsa Hi,

        Maybe your first 4 lines overrides the other definitions because they are global. Try to enclose them in QPushButton{...}

        QPushButton {
            background-color: rgb(51, 153, 204);
            ...
        }
        QPushButton:pressed {
            background-color: rgb(224, 0, 0);
            ...
        }
        
        T Offline
        T Offline
        testevpsa
        wrote on last edited by
        #3

        Hello @Gojir4 , you are completely right!
        Thank you for your help!

        1 Reply Last reply
        0
        • Gojir4G Gojir4

          @testevpsa Hi,

          Maybe your first 4 lines overrides the other definitions because they are global. Try to enclose them in QPushButton{...}

          QPushButton {
              background-color: rgb(51, 153, 204);
              ...
          }
          QPushButton:pressed {
              background-color: rgb(224, 0, 0);
              ...
          }
          
          A Offline
          A Offline
          Austrolog
          wrote on last edited by
          #4

          @Gojir4 Hi, where did youn find ":pressed"? I tried to search it on the documentation but it doesn't mention about pressed

          JonBJ 1 Reply Last reply
          0
          • A Austrolog

            @Gojir4 Hi, where did youn find ":pressed"? I tried to search it on the documentation but it doesn't mention about pressed

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Austrolog
            https://doc-snapshots.qt.io/qt6-dev/stylesheet-reference.html#list-of-pseudo-states
            https://doc-snapshots.qt.io/qt6-dev/stylesheet-examples.html#customizing-qpushbutton

            A 1 Reply Last reply
            2
            • JonBJ JonB

              @Austrolog
              https://doc-snapshots.qt.io/qt6-dev/stylesheet-reference.html#list-of-pseudo-states
              https://doc-snapshots.qt.io/qt6-dev/stylesheet-examples.html#customizing-qpushbutton

              A Offline
              A Offline
              Austrolog
              wrote on last edited by
              #6

              @JonB thank you

              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