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 set the background color for QPushButtons and QCheckBoxes?
Forum Updated to NodeBB v4.3 + New Features

How can I set the background color for QPushButtons and QCheckBoxes?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.6k 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.
  • C Offline
    C Offline
    cscooper
    wrote on last edited by
    #1

    I'm trying to change the background color of a QAbstractButton (either a QPushButton or QCheckBox) in Qt5 and having zero luck.

    This does nothing:

    @pButton->setAutoFillBackground(true);
    QPalette palette = pButton->palette();
    palette.setColor(QPalette::Window, QColor(Qt::blue));
    pButton->setPalette(palette);
    pButton->show();@

    and if I try changing the style sheet:

    @pButton->setStyleSheet("background-color: rgb(255,255,0);");@

    then Qt throws up its hands and draws an afwul-looking blocky button.

    There is a page titled "How to change the background color of QWidget" but it just talks about those two methods.

    There is also a page "Qt Style Sheets Examples" that implies that if you want to change the background color, you have to take over all aspects of drawing the button, which just seems like overkill.

    I need this to run on Mac, Windows, and Ubuntu Linux, and it's really not a happy thing if I have to manually draw everything about the button 3 times (once for each platform).

    Am I missing something obvious?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cscooper
      wrote on last edited by
      #2

      And by "background color" I mean the area surrounding the button, not the color behind the text on the face of the button.

      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