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 .setToolTip("text") on a widget. This is often used to assist the user.

Related Course: Create GUI Apps with Python PyQt5

Tooltip example

PyQt tooltip example

The program below adds tooltip messages to the buttons. This can be either plain text or HTML formatted tags (the tags bold and italic work).
A simple tooltip would be:

1
2
button = QPushButton("Button")
button.setToolTip("This is a text")

But you can add HTML formatting to your tooltip, making it look like this:

1
2
button = QPushButton("Button")
button.setToolTip("<b>HTML</b> <i>can</i> be shown too..")

Example tooltip

You can set any message you want inside the tooltip message. In the program below two buttons are added.
Each button has a different tooltip, which is shown when you hover over the button.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from PyQt5.QtWidgets import *
import sys

class Window(QWidget):

def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)

button = QPushButton("Button")
button.setToolTip("This is a text")
layout.addWidget(button, 0, 0)

button = QPushButton("Button")
button.setToolTip("<b>HTML</b> <i>can</i> be shown too..")
layout.addWidget(button, 1, 0)

app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())

If you are new to Python PyQt, then I highly recommend this book.

Download Examples