Important: Please read the Qt Code of Conduct -

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:

    1. 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?

    2. 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":, especially "Customizing Qt Widgets Using Style Sheets" and look for QToolButton in "Qt Style Sheets Reference".

  • See the ColorRole section of the "QPalette": 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":, but I think that may be more effort than is needed in this case.

  • Yes, use stylesheets:
    setStyleSheet(QString("QToolButton:selected { background-color: #FIND_ORANGE_COLOR; }"));

  • Thank you very much for the fast answers! I could not test it, yet but I think I will be able to do it now and read the documents carefully.

  • Thanks again for your tipps. I got it working now. Still I have two followup questions:

    1. 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?

    2. 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?

  • Ok, thanks, I found the information I was looking for in the pseudo-states section of the style sheet reference - I did not know this site before.

Log in to reply