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. QPushButton background color not working
Forum Updated to NodeBB v4.3 + New Features

QPushButton background color not working

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 17.1k Views 1 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
    asanchez1987
    wrote on last edited by
    #1

    Hi,

    I'm trying to color the background of a QPushButton, but it does not work.

    @
    QPushButton* blau = new QPushButton("Blau", &F);
    QPalette pal_blau = blau->palette();
    pal_blau.setColor(QPalette::Button, QColor(0,0,255));
    blau->setPalette(pal_blau);
    blau->setAutoFillBackground(true);
    @

    Using gnome 2.28.2 on Centos 6.3

    It seems that there is a little border in blue around the button, but the button background has no color changed.

    Any suggestions?

    Thank you

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Shouldn't you try it using the stylesheet? Much easier and can be done in designer.
      greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • A Offline
        A Offline
        asanchez1987
        wrote on last edited by
        #3

        I would like to do it using QPalette

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          Change line 3 with :
          @
          pal_blau.setColor(QPalette::Background, QColor(0,0,255)
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            asanchez1987
            wrote on last edited by
            #5

            It does not work either :/

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #6

              Well, I think for settings buttons background color, style sheet is the way to go ... (I think Qt use OS theme effect, hence some palette modifications don't have any effect)

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                The documentation on QPalette states:
                [quote]
                Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the Mac OS X styles.[/quote]

                So, basically, most rendering on popular, modern OS's bypasses the palette completely.

                Using style sheets really is the only relyable way.

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

                  Maybe this helps you out: "How_to_Change_the_Background_Color_of_QWidget":http://qt-project.org/wiki/How_to_Change_the_Background_Color_of_QWidget

                  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