QPushButton color on MacOSX
Unsolved
General and Desktop
-
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?
Any other suggestions? Thanks!
-
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.