Home > Backend Development > Python Tutorial > PyQt5 tooltip function that you must learn every day

PyQt5 tooltip function that you must learn every day

不言
Release: 2018-04-19 10:31:59
Original
2867 people have browsed it

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(&#39;这是一个 <b>QWidget</b> 控件&#39;)

    btn = QPushButton(&#39;按钮&#39;, self)
    btn.setToolTip(&#39;这是一个 <b>QPushButton</b> 控件&#39;)
    btn.resize(btn.sizeHint())
    btn.move(50, 50)

    self.setGeometry(300, 300, 300, 220)
    self.setWindowTitle(&#39;工具提示&#39;)    
    self.show()

if __name__ == &#39;__main__&#39;:

  app = QApplication(sys.argv)
  ex = Example()
  sys.exit(app.exec_())
Copy after login

In this example, we display tooltips for two PyQt5 controls.

 QToolTip.setFont(QFont(&#39;楷体&#39;, 14))
Copy after login

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(&#39;按钮&#39;, self)
btn.setToolTip(&#39;这是一个 <b>QPushButton</b> 控件&#39;)
Copy after login

We create a button control and set the tooltip of the control.

 btn.resize(btn.sizeHint())
 btn.move(50, 50)
Copy after login

Set the size and position of the button control in the form. The sizeHint() method gives the button a recommended size.

After program execution

PyQt5 tooltip function that you must learn every day

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template