
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QToolTip
QToolTip is a component of PyQt that allows developers to provide contextual information about various elements within their graphical user interfaces. These tooltips are displayed when the user hovers over an item, offering brief descriptions, helpful hints, or additional information.
Basic Usage of Tooltip
Integrating tooltips into PyQt applications is straightforward. We can set tooltips for any widget that inherits from QWidget using the setToolTip() method. Here's a basic example −
In the below example, when we hover over the QPushButton, it will display the tooltip "This is a QPushButton."
import sys from PyQt6.QtWidgets import QApplication, QPushButton def main(): app = QApplication(sys.argv) button = QPushButton('Hover Me') button.setToolTip('This is a QPushButton') button.show() sys.exit(app.exec()) if __name__ == '__main__': main()
Output

Advanced Usage
QToolTip offers various customization options, including adjusting the tooltip's font, background color, and timing of display. We can use this customization features by subclassing QToolTip and overriding its default behavior.
In the below example, we use the customization feature of tooltip to customize the font of the tooltip to Arial with a size of 12.
import sys from PyQt6.QtWidgets import QApplication, QPushButton, QToolTip from PyQt6.QtGui import QFont def main(): app = QApplication(sys.argv) button = QPushButton('Hover Me') button.setToolTip('This is a QPushButton') QToolTip.setFont(QFont('Arial', 12)) button.show() sys.exit(app.exec()) if __name__ == '__main__': main()
Output

Methods used in QTooltip
Method | Description |
---|---|
setToolTip() | Sets the tooltip for a widget. |
setFont() | Sets the font used for tooltips. |
setPalette() | Sets the palette used for tooltips, including background and foreground colors. |
showText() | Displays a tooltip with specified text. |
hideText() | Hides the currently displayed tooltip. |
Example 1: Tooltip with Image
In this example, we will create a tooltip which will displays a tooltip with an image when hovering over the button.
import sys from PyQt6.QtWidgets import QApplication, QPushButton, QToolTip from PyQt6.QtGui import QFont, QPixmap def main(): app = QApplication(sys.argv) button = QPushButton('Hover Me') button.setToolTip('') button.show() sys.exit(app.exec()) if __name__ == '__main__': main()
Output
The above code produces the following output −

Example 2: Tooltip with HTML Formatting
In the below example, the tooltip text is formatted using HTML, displaying a blue-colored header.
import sys from PyQt6.QtWidgets import QApplication, QPushButton, QToolTip def main(): app = QApplication(sys.argv) button = QPushButton('Hover Me') button.setToolTip('This is a QPushButton
') button.show() sys.exit(app.exec()) if __name__ == '__main__': main()
Output
The above code produces the following output −

Example 3: Custom Tooltip Duration
In this example, the tooltip is displayed for 3 seconds after hovering over the button.
import sys from PyQt6.QtWidgets import QApplication, QPushButton, QToolTip from PyQt6.QtCore import QTimer def main(): app = QApplication(sys.argv) button = QPushButton('Hover Me') button.setToolTip('This is a QPushButton') timer = QTimer() timer.setSingleShot(True) timer.timeout.connect(lambda: button.setToolTip('')) button.enterEvent = lambda event: timer.start(3000) button.show() sys.exit(app.exec()) if __name__ == '__main__': main()
Output
The above code produces the following output −
