Home >Backend Development >Python Tutorial >PyQt5 tooltip function that you must learn every day
This article mainly introduces in detail the tool tip function of PyQt5 that you must learn every day. It has a certain reference value. Interested friends can refer to it.
This article will teach us how to use PyQt5 controls. Tooltip function.
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ PyQt5 教程 这个例子显示了窗口和按钮气泡工具提示。 作者:我的世界你曾经来过 博客:http://blog.csdn.net/weiaitaowang 最后编辑:2016年7月29日 """ import sys from PyQt5.QtWidgets import (QApplication, QWidget, QToolTip, QPushButton) from PyQt5.QtGui import QFont class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): QToolTip.setFont(QFont('楷体', 14)) self.setToolTip('这是一个 <b>QWidget</b> 控件') btn = QPushButton('按钮', self) btn.setToolTip('这是一个 <b>QPushButton</b> 控件') btn.resize(btn.sizeHint()) btn.move(50, 50) self.setGeometry(300, 300, 300, 220) self.setWindowTitle('工具提示') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
In this example, we display tooltips for two PyQt5 controls.
QToolTip.setFont(QFont('楷体', 14))
This static method sets the font used for tool tips, we use 10px size with italic font
self.setToolTip('This is AQWidget control')
Create a tool tip for this window control. We use the setTooltip() method. We can use rich text format for the displayed text.
btn = QPushButton('按钮', self) btn.setToolTip('这是一个 <b>QPushButton</b> 控件')
We create a button control and set the tooltip of the control.
btn.resize(btn.sizeHint()) btn.move(50, 50)
Set the size and position of the button control in the form. The sizeHint() method gives the button a recommended size.
After program execution
Related recommendations:
python greedy matching and multi-line matching
Python deduplicates multi-attribute duplicate data
The above is the detailed content of PyQt5 tooltip function that you must learn every day. For more information, please follow other related articles on the PHP Chinese website!