How to get native OS colors
-
Hi,
I am currently working on a PyQt5 application with Python 3.9.0.
I would like to get the native operating system colors to apply them to my QPushButton.
I would like the "send" button in the attached image to have the same color as the "single device" tab.
This is also the color shown when pressing the button.
I hope the link works, I am not too familiar with imgur.Is there a way for me to obtain these native colors? I haven't been able to find any relevant information on this and I doubt I am the only one trying to do this.
Thanks for the help!
-
Hi and welcome to devnet,
If memory serves well it should happen if you make it the default button. See QDialogButtonBox.
-
Hi SGaist,
Thanks for the quick reply. Yes this works, I used the setDefault function on the button.
Still, is there a way to obtain these colors? Lets say I wanted to apply it to something other than a button. Is there a similar method for the other object types?
As a random example, lets say I wanted this color as the background of a group box, would that be possible?
Thanks!
-
That's not a good idea. You would go against the platform user interface guidelines which is something that your users won't like.
-
Hi SGaist,
Why wouldn't this be a good idea? I just want to obtain the default OS colors and apply them to some widgets.
I could decide to recolor everything the same shade of blue but I would prefer to obtain the actual OS colors.
The users are myself and a few colleagues, this is an internal tool.Is there a way to do this?
Thanks!
-
Because that kind of highlighting is used for specific purposes. Applied it to any and all controls does not make things clearer. Rather the contrary. Why would a QGroupBox all of a sudden get the same blue background as a selected tab ?
You can get the information from QPalette.
-
Hi SGaist,
Thanks for the clarification, that does make sense.
We weren't planning on using the color for anything other than buttons but were curious to see if it was available.However, when playing around with QPalette, we were unable to obtain the color we mentioned in our previous post.
Any idea which field is the one we are looking for?
We tried all of the ColorRoles and the ColorGroups.Thanks for the information, very appreciated!
-
I would have gone with
QPalette::Highlight