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 | button = QPushButton("Button") |
But you can add HTML formatting to your tooltip, making it look like this:
1 | button = QPushButton("Button") |
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 | from PyQt5.QtWidgets import * |
If you are new to Python PyQt, then I highly recommend this book.