Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Button color not changing on macOS in Qt

I am trying to change the color of QPushButton to QPalette::Accent, but the color does not change.

At first I tried to do it this way:

 QPushButton button("Apply");
 QPalette palette = QPalette();
 palette.setColor(QPalette::Button, palette.color(QPalette::Accent));
 button.setPalette(palette);
 button.setAutoFillBackground(true);

But I only got this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

button1

When I tried to use stylesheet I got a button that lost its macOS style

QPushButton* button = new QPushButton("open");
 button->setStyleSheet("background-color: rgb(255,255,0);");

button2

But I want to achieve this result:

button3

I apologize for the stupid question, but I have already searched the entire Internet, and I don’t know how to do it.

>Solution :

A blue button in MacOS, like in your example "button3", indicates that this is a default button. So, e.g. pressing Enter will press this button.

To achieve the same behavior (and look), you should simply call button.setDefault(true). This might be restricted to dialog windows.

Coloring the button blue without making it the default button would mislead the user.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading