I've been adding tooltips to an app that I've been writing, and had issues with the colour of the tooltip text.
The app has a number of buttons, which change background and text colour depending on what the status of the button is. The text is either white or black.
The tooltip text colour always seems to follow the colour of the button text. When the text on the button is white, then it's all fine, but if the text on the button is black, then the tooltip is black text on a black background. What I want to be able to have is the tooltip to always be white text on black, whatever the button's colour.
For this, I was setting my tooltip using:
self.setToolTip(toolTip)
Now I did find a potential solution to this, but it had its own issues:
self.setToolTip("<font color=white>%s</font>" % toolTip.replace("\n", "<br/>"))
However, when I do this, the lines in my tooltip start wrapping, rather than keeping the full line length on one line, which is what I want it to do.
Any suggestions on either how to change the tooltip colour without using HTML, or how to get the HTML-based tooltip to not wrap?
Thanks
A tooltip is a message that is shown when hovering the mouse on a widget. In PyQt you can add tooltips to widgets, which then show small hints when hovering over the widget. This can be a plain text message or a formatted message (HTML). You can add a tooltip by calling .
You can change the background color of the tooltip in the slider using the tooltipBackgroundColor property. You must import the theme.
You can use a stylesheet, for example:
self.setStyleSheet("""QToolTip {
background-color: black;
color: white;
border: black solid 1px
}""")
There is more information available at:
http://doc.qt.io/qt-4.8/stylesheet-examples.html#customizing-qtooltip
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With