PyQt5 Quick Reference Manual

PyQt Quick Reference Manual

PyQt is a toolkit for creating GUI applications. It is a successful fusion of the Python programming language and the Qt library. The Qt library is currently one of the most powerful libraries.

PyQt was developed by Phil Thompson. PyQt implements a set of Python modules. It has more than 300 categories and nearly 6000 functions and methods. It is a multi-platform toolkit that can run on all major operating systems, including UNIX, Windows and Mac. PyQt uses dual licenses, and developers can choose between GPL and commercial licenses. Prior to this, the GPL version can only be used on Unix. Starting from version 4 of PyQt , the GPL license can be used on all supported platforms.

Here are some descriptions of commonly used PyQt controls and properties for easy query

installation method:

pip install PyQt5 # 安装pyqt5
pip install pyqt5-tools # 安装工具包
# 建议从清华镜像源下载安装 -i https://pypi.tuna.tsinghua.edu.cn/simple

Designer

PyQt provides a Pycharm extension toolkit- pyqt5-tools

After the installation is complete, you can use the designer command in the terminal to open the interface editor, and use the editor to help you better layout the window.

After the layout is completed, save it as name.ui file

The corresponding py file can be generated by the following instructions

pyuic5 -o name.py name.ui

Call the py file generated by Designer

from PyQt5.QtWidgets import QApplication, QMainWindow
# 当按钮调用有多个参数输入时 partial(button_event,**arg)
from functools import partial
import name # 此处designer生成的py包
import sys

if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = Window1.Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    # 按钮的简单调用 窗口实例.按钮实例.clicked.connect
    # ui.button.clicked.connect(partial(button_event, arg1, arg2))
    # ui.button.clicked.connect(button_event)
    sys.exit(app.exec_())

Module

  1. QtCore

    • Contains core non-GUI functions. This module is used to process time, files and directories, various data types, streams, URLs, MIME types, threads or processes
  2. QtGui

    • Contains window-like system integration, event processing, two-dimensional graphics, basic imaging, fonts and text.

    • QFont

      • QFont('SansSerif',6) # 生成一个可识别的QFont实例(字体,大小)
        
    • QIcon

      • QIcon('.png') # 生成一个可识别的QIcon实例
        
  3. QtWidgets

    • The module contains classes for creating a classic desktop style user interface that provides a set of UI elements.

    • QApplication

      • Every pyqt5 application must create an application object. The sys.argv parameter is a list, input parameters from the command line.

      • import sys
        from PyQt5.QtWidgets import QApplication # 这是模块导包的示范
        app = QApplication(sys.argv)
        
    • QMessageBox

      • Some already written message pop-up styles

      • QMessageBox.information information box
        QMessageBox.question question and answer box
        QMessageBox.ctitical dangerous
        QMessageBox.about About

    • QPushButton

      • Button

      • btn = QPushButton('按钮名',self) # 按钮实例化
        btn.resize(btn.sizeHint()) # btn.sizeHint()显示默认尺寸
        btn.move(50,50) # 移动按钮窗口位置
        
    • QToolTip

    • QWidget

      • The base class of all user interface objects in pyqt5. He provides a default constructor for QWidget. The default constructor has no parent class.

      • w = QWidget()
        w.resize(250, 150) # resize()方法调整窗口的大小,这里是 250px 宽、150px 高。
        w.move(300, 300) # move()方法移动窗口在屏幕上的位置到x = 300,y = 300坐标。
        w.setWindowTitle('title') # 设置窗口的标题
        w.show() # 显示在屏幕上
        # ———其他操作———
        
        # 系统exit()方法确保应用程序干净的退出
        # 的exec_()方法有下划线。因为执行是一个Python关键词。因此,exec_()代替
        sys.exit(app.exec_())
        
  4. QtMultimedia

    • Contains classes to handle multimedia content and APIs to access camera and radio functions.
  5. QtBluetooth

    • The module contains classes of scanning devices and connecting and interacting with them. The description module contains classes for network programming. These classes facilitate the encoding of TCP and IP and UDP clients and servers, making network programming easier and more portable.
  6. QtNetwork

  7. QtPositioning

    • Contains the use of various possible sources to determine the location, including satellite, Wi-Fi, or a text file.
  8. Enginio

    • The module implements the client library to access the application runtime hosted by Qt Cloud Service.
  9. QtWebSockets

    • The module contains classes that implement the WebSocket protocol.
  10. QtWebKit

    • Contains a web browser implementation class based on the Webkit2 library.
  11. QtWebKitWidgets

    • The basic webkit1 of the included classes is used for the realization of the qtwidgets application web browser.
  12. QtXml

    • Contains classes with XML files. This module provides implementations for SAX and DOM API.
  13. QtSvg

    • Provides classes for displaying the contents of SVG files. Scalable Vector Graphics (SVG) is a language for describing two-dimensional graphics and graphics applications.
  14. QtSql

    • Provides classes for operating the database.
  15. QtTest

    • Contains the function of unit testing for PyQt5 applications.

Guess you like

Origin blog.csdn.net/weixin_46251846/article/details/109158973