QToolButton setStyleSheet sets stylesheet on tooltip

  • Hello

    I have a problem with a QToolButton. It is placed on a dark background, so the button textcolor is set to white with the stylesheet
    @helpButton->setStyleSheet("color: white;");@

    And it works great. The problem is, that the button also has a tooltip, but now the textcolor of the tooltip is also set to white, but the tooltip background is almost white, so the text is not visible.

    My question is, how do I set a stylesheet on my button that sets the textcolor to white, but keeps the original tooltip textcolor?

    I have tried
    @helpButton->setStyleSheet("QToolButton{ color: white;}");@
    @helpButton->setStyleSheet("color: white; QToolTip{ color: black;}");@
    And other variations, but without the desired effect.

  • You could try to use the decendant selector:
    QToolButton { color: white;}
    QToolButton QWidget { color: black;}

    I am using QWidget, because I don't know of what class the actual popup is. It is not QToolTip; the actual class seems to be private.

  • so, the first solution sets the color for everything to white. And style sheets are used in child widgets as well, so for the first version, the result is clear.

    But the second one should work.

  • I tried
    @helpButton->setStyleSheet("QToolButton { color: white;} QToolButton QWidget { color: black;}");@
    and it works perfectly. Thank you for a fast and great solution :)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.