You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
880 B

import sys
from PyQt6.QtWidgets import (QWidget, QToolTip,
QPushButton, QApplication)
from PyQt6.QtGui import QFont
def create_tooltip_widget():
app = QApplication(sys.argv)
# 创建基本的QWidget
widget = QWidget()
# 设置提示字体
QToolTip.setFont(QFont('SansSerif', 10))
# 设置QWidget的提示信息
widget.setToolTip('This is a <b>QWidget</b> widget')
# 创建QPushButton
button = QPushButton('Button', widget)
button.setToolTip('This is a <b>QPushButton</b> widget')
# 设置按钮大小和位置
button.resize(button.sizeHint())
button.move(50, 50)
# 设置窗口大小和标题
widget.setGeometry(300, 300, 300, 200)
widget.setWindowTitle('Tooltips')
# 显示窗口
widget.show()
# 运行应用
sys.exit(app.exec())
if __name__ == '__main__':
create_tooltip_widget()