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 color on MacOSX

QPushButton color on MacOSX

Scheduled Pinned Locked Moved Unsolved General and Desktop
combobox macosmac ospushbuttonqpushbuttoncolor change
2 Posts 2 Posters 605 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.
  • C Offline
    C Offline
    cady
    wrote on 28 Oct 2022, 16:23 last edited by
    #1

    I am running out of ideas... how do I color the background of a QPushButton while keeping the OS style?
    I am using Qt 5.15 on Mac OSX 12.4.

    Here is what I have tried in a sample application. I have a MainWindow with a GridLayout and few controls, including a QPushButton and a QComboBox. I have the same issue with both the button and the combo box.

    Here is my code:

        QPalette newPal = ui->pushButton->palette();
        newPal.setColor(QPalette::ButtonText, QColor(Qt::white)); // Yes, this updates the text color
        newPal.setColor(QPalette::Button, QColor(Qt::blue)); // Nope, doesn't update the background
        newPal.setColor(QPalette::Window, QColor(Qt::blue)); // Nope
        newPal.setColor(QPalette::Base, QColor(Qt::blue)); // Another nope
        newPal.setColor(QPalette::Active, QPalette::Button, QColor(Qt::blue)); // Still nope
        newPal.setColor(QPalette::Inactive, QPalette::Button, QColor(Qt::blue)); // Nope
        // ui->pushButton->setBackgroundRole(QPalette::Button); // Doesn't change anything, should already be using that role anyway
        // ui->pushButton->setAutoFillBackground(true); // Paints the blue on the background BEHIND the button
        // ui->pushButton->setStyleSheet("background-color: blue"); // Works, but loses the MacOS styling, switch to Windows styling
        // ui->pushButton->setStyle(QStyleFactory::create("Macintosh")); // This doesn't even help the above, it keeps the Windows looking control
        // ui->pushButton->setStyleSheet("border: none"); // Makes the button totally disappear
        ui->pushButton->setPalette(newPal);
        ui->pushButton->update(); // Probably not needed?
    

    Imgur https://imgur.com/s5tUumR

    Any other suggestions? Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Oct 2022, 18:57 last edited by
      #2

      Hi,

      The system style are free to ignore hints in order to stay coherent with the OS guide lines so you are likely hitting that.

      One possible way is to create a QProxyStyle.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      28 Oct 2022, 16:23

      • Login

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