A tooltip is a message that is shown when hovering the mouse on a 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:
PyQt Desktop Apps with Python
icon

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).

You can set any message you want inside the tooltip message.

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_())