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. Question about setting Push button background color
Forum Updated to NodeBB v4.3 + New Features

Question about setting Push button background color

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 4.5k 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.
  • D Offline
    D Offline
    dalishi
    wrote on 29 Jul 2022, 10:03 last edited by dalishi
    #1

    Hi, Im setting my push button background color by:

    ui->colorPushButton->setStyleSheet("QPushButton { background-color : blue }");
    

    The color changes only when I press the button, and changes back when my click releases. How to change the background color even I don't touch the button? Thanks.
    Screenshot from 2022-07-29 17-08-22.png

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 29 Jul 2022, 11:44 last edited by mrjj
      #2

      Hi
      The part of the code that draws the frame/border doesn't use the background color for the background.
      the trick is to remove the border and then it shows

      QPushButton { 
       border:  none;
      background-color : blue;
      }
      

      alt text

      D 1 Reply Last reply 30 Jul 2022, 15:25
      1
      • J Offline
        J Offline
        JoeCFD
        wrote on 29 Jul 2022, 15:38 last edited by JoeCFD
        #3

        @dalishi said in Question about setting Push button background color:

        setStyleSheet("QPushButton { background-color : blue }");

        Not sure about your question. The setting seems OK. What is the color on your machine when the button is not pressed?
        On my machine, the color is same as yours. It becomes a bit darker when the button is pressed.

        D 1 Reply Last reply 30 Jul 2022, 15:26
        0
        • M mrjj
          29 Jul 2022, 11:44

          Hi
          The part of the code that draws the frame/border doesn't use the background color for the background.
          the trick is to remove the border and then it shows

          QPushButton { 
           border:  none;
          background-color : blue;
          }
          

          alt text

          D Offline
          D Offline
          dalishi
          wrote on 30 Jul 2022, 15:25 last edited by
          #4

          @mrjj Hi you solution works like a charm! Thanks bro.

          1 Reply Last reply
          0
          • J JoeCFD
            29 Jul 2022, 15:38

            @dalishi said in Question about setting Push button background color:

            setStyleSheet("QPushButton { background-color : blue }");

            Not sure about your question. The setting seems OK. What is the color on your machine when the button is not pressed?
            On my machine, the color is same as yours. It becomes a bit darker when the button is pressed.

            D Offline
            D Offline
            dalishi
            wrote on 30 Jul 2022, 15:26 last edited by
            #5

            @JoeCFD if not pressed, it is just like the default push button color, grey? @mrjj 's method solved my problem.

            1 Reply Last reply
            0

            1/5

            29 Jul 2022, 10:03

            • Login

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