Python

pyqt5 tooltip

A tooltip is a hint in a graphical interface.

Tooltips frequently appear when hovering the mouse over a widget (without clicking). Pyqt supports tool tips, they can be configured for widgets.

pyqt tooltip

Related course:
Create Simple GUI Applications with Python and Qt

Note: Tooltips are not shown on mobile devices because there’s no mouse cursor.

Pyqt5 tooltip

A tooltip can be set using a widgets setTooltip method.

pybutton.setToolTip('This is a tooltip for the QPushButton widget')  

The setToolTip() method sets the tooltip message for a QtWidget.

Copy/paste example:

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QWidget, QPushButton
from PyQt5.QtCore import QSize

class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)

self.setMinimumSize(QSize(300, 100))
self.setWindowTitle("PyQt tooltip example - pythonprogramminglanguage.com")

pybutton = QPushButton('Pyqt', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(100,32)
pybutton.move(50, 20)
pybutton.setToolTip('This is a tooltip message.')

def clickMethod(self):
print('PyQt')

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )

Previous Post Next Post

Cookie policy | Privacy policy | ©

PyQt