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 can I repaint my QPushButton

How can I repaint my QPushButton

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5.5
8 Posts 5 Posters 4.0k 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by A Former User
    #1

    I'm using Qt5.5 to develop my program.
    Here is part of my code

    Actually i wanna print color green on this Button.

    But it didn't work, it still no color.
    I'm sure there is no error when i compile it.
    But why it doesn't work?
    Please Help!

    RatzzR 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Can u try with style sheet for your requirements?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      5
      • V victor wang

        I'm using Qt5.5 to develop my program.
        Here is part of my code

        Actually i wanna print color green on this Button.

        But it didn't work, it still no color.
        I'm sure there is no error when i compile it.
        But why it doesn't work?
        Please Help!

        RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on last edited by Ratzz
        #3

        @victor-wang
        Doc says http://doc.qt.io/qt-4.8/qpalette.html#details

        We strongly recommend that you use the default palette of the current style (returned by QApplication::palette()) and modify that as necessary. This is done by Qt's widgets when they are drawn.
        
        To modify a color group you call the functions setColor() and setBrush(), depending on whether you want a pure color or a pixmap pattern.
        

        Here is an example which may help you .

        One more simple example is here .

        --Alles ist gut.

        V 1 Reply Last reply
        0
        • RatzzR Ratzz

          @victor-wang
          Doc says http://doc.qt.io/qt-4.8/qpalette.html#details

          We strongly recommend that you use the default palette of the current style (returned by QApplication::palette()) and modify that as necessary. This is done by Qt's widgets when they are drawn.
          
          To modify a color group you call the functions setColor() and setBrush(), depending on whether you want a pure color or a pixmap pattern.
          

          Here is an example which may help you .

          One more simple example is here .

          V Offline
          V Offline
          victor wang
          wrote on last edited by
          #4

          @Ratzz
          Sorry, i can't see any thing in your example.
          Could u post again?

          RatzzR 1 Reply Last reply
          0
          • V victor wang

            @Ratzz
            Sorry, i can't see any thing in your example.
            Could u post again?

            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by
            #5

            @victor-wang
            Did you read the doc I posted?

            --Alles ist gut.

            V 1 Reply Last reply
            0
            • cfdevC Offline
              cfdevC Offline
              cfdev
              wrote on last edited by
              #6

              A way by style sheet:

              ui->pushButton->setStyleSheet("background:#CC892B;");
              
              1 Reply Last reply
              0
              • RatzzR Ratzz

                @victor-wang
                Did you read the doc I posted?

                V Offline
                V Offline
                victor wang
                wrote on last edited by
                #7

                @Ratzz
                Yes, i assume that it means i have to change the code like this

                ui->pushbuttonpt_land_resultlight->setpalette(QApplication::palette())
                

                I'm not quite sure so i want to see the example to evidence my hypothesis.
                Am i right?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mostefa
                  wrote on last edited by mostefa
                  #8

                  Hi @victor-wang

                  To set the color of your pushbutton with qpalette you have to do something like this:

                  QPalette palette = ui->pushButton->palette();
                  palette.setColor(QPalette::Button,Qt::green);
                  ui->pushButton->setPalette(palette);
                  

                  The result will be then similar to something like this:
                  alt text

                  If want change it to a custom color , you can use hex color code

                  palette.setColor(QPalette::Button,QColor("#FF0000")); // #FF0000 is for red color you can change it.
                  

                  This should work for you,

                  1 Reply Last reply
                  1

                  • Login

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