Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the text colour of a tooltip in PyQt

Tags:

python

qt4

pyqt4

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

like image 970
Hugh Avatar asked Jul 27 '13 16:07

Hugh


People also ask

What is tooltip in pyqt5?

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 .

How do you change the background color on tooltip in flutter?

You can change the background color of the tooltip in the slider using the tooltipBackgroundColor property. You must import the theme.


1 Answers

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

like image 50
Radio- Avatar answered Sep 20 '22 22:09

Radio-