QToolButton: orange background?
-
I am using a number of QToolButtons. When you only provide one icon for the button, Qt automatically enhances the icon when the mouse is over (active) and also draws a sunken border around it, when pressed. This is fine, but for my purpose I need pressed icons to stand out more. So I would like to have a orange coloured background for "selected" buttons.
I see two ways to get there:
-
It is possible to define another selfmade icon for the different modes/states. And in principle I also managed to set my own icon for the selected mode. BUT: The automatic drawing of the sunken border is not switched off. So in selected mode the icon has now two borders, my own orange one and around that the automatic one provided by Qt. So is there a way to switch the automatic drawing/enhancement off if I provide my own icons for the different modes anyway?
-
Would it be possible to set the background colour of the sunken border so that I do not need to provide my own icons? Can I set it using style sheets? If so it would be nice if you could point me in the right direction.
Thank you very much!
-
-
Style sheets are way to go. Check "Docs":http://qt-project.org/doc/qt-4.8/stylesheet.html, especially "Customizing Qt Widgets Using Style Sheets" and look for QToolButton in "Qt Style Sheets Reference".
-
See the ColorRole section of the "QPalette":http://qt-project.org/doc/qt-4.8/qpalette.html documentation... customizing the different color roles may yield the desired effect. Alternatively, you can set QPalette::Button (or maybe QPalette::Window or QPalette::Base?) to transparent and then use your custom bevel icon.
There are also ways of programatically creating such borders (see e.g. "QRubberBand":http://qt-project.org/doc/qt-4.8/qrubberband.html), but I think that may be more effort than is needed in this case.
-
Thanks again for your tipps. I got it working now. Still I have two followup questions:
-
QToolButton:selected did not work in my example. I found out that one can use QToolButton:pressed for the appearance while the button is still pressed and QToolButton:checked if the button is checkable and stays in the pressed position.
It took me quite a while and in the end I had to guess that ":checked" is the right way to go. Is there a documentation about which styles can be set and which possible values might be set? I found a few examples in the Qt Style Sheets Reference but it's far from beeing complete. I also found "border-style: inset" interesting but it is not easy for me to find out which other styles appart from "inset" are available. Is there a good place to look for it? -
When the button is pressed the content of the icon is moved in bottom right direction to support the feeling that the button is pressed. Can this be controlled anywhere?
-
-
"this":http://qt-project.org/doc/qt-4.8/stylesheet-reference.html and "this":http://qt-project.org/doc/qt-4.8/stylesheet.html contain a lot of info on style-sheets