Pyqt5 简明教程
PyQt5 - Major Classes
PyQt API 是一个包含大量类和方法的集合。这些类在 20 多个模块中进行定义。
PyQt API is a large collection of classes and methods. These classes are defined in more than 20 modules.
以下是经常使用的一些模块 −
Following are some of the frequently used modules −
Sr.No. |
Modules & Description |
1 |
QtCore Core non-GUI classes used by other modules |
2 |
QtGui Graphical user interface components |
3 |
QtMultimedia Classes for low-level multimedia programming |
4 |
QtNetwork Classes for network programming |
5 |
QtOpenGL OpenGL support classes |
6 |
QtScript Classes for evaluating Qt Scripts |
7 |
QtSql Classes for database integration using SQL |
8 |
QtSvg Classes for displaying the contents of SVG files |
9 |
QtWebKit Classes for rendering and editing HTML |
10 |
QtXml Classes for handling XML |
11 |
QtWidgets Classes for creating classic desktop-style UIs. |
12 |
QtDesigner Classes for extending Qt Designer |
13 |
QtAssistant Support for online help |
PyQt5 开发工具是一系列用于 Qt 开发的有用实用程序。以下是此类实用程序的精选列表 −
PyQt5 development tools is a collection of useful utilities for Qt development. Following is a select list of such utilities −
Sr.No. |
Tool Name & Description |
1 |
assistant Qt Assistant documentation tool |
2 |
pyqt5designer Qt Designer GUI layout tool |
3 |
linguist Qt Linguist translation tool |
4 |
lrelease compile ts files to qm files |
5 |
pylupdate5 extract translation strings and generate or update ts files |
6 |
qmake Qt software build tool |
7 |
pyqt5qmlscene QML file viewer |
8 |
pyqmlviewer QML file viewer |
9 |
pyrcc5 Qt resource file compiler |
10 |
pyuic5 Qt User Interface Compiler for generating code from ui files |
11 |
pyqmltestrunner running unit tests on QML code |
12 |
qdbus command-line tool to list D-Bus services |
13 |
QDoc documentation generator for software projects. |
14 |
Qhelpgenerator generating and viewing Qt help files. |
15 |
qmlimportscanner parses and reports on QML imports |
PyQt API 包含 400 多个类。 QObject 类位于类层次结构的顶部。它是所有 Qt 对象的基类。此外, QPaintDevice 类是所有可绘制对象的基类。
PyQt API contains more than 400 classes. The QObject class is at the top of class hierarchy. It is the base class of all Qt objects. Additionally, QPaintDevice class is the base class for all objects that can be painted.
QApplication 类管理 GUI 应用程序的主设置和控制流。它包含主事件循环,在该循环中处理和分派由窗口元素和其他源生成的事件。它还处理系统范围和应用程序范围的设置。
QApplication class manages the main settings and control flow of a GUI application. It contains main event loop inside which events generated by window elements and other sources are processed and dispatched. It also handles system-wide and application-wide settings.
QWidget 类派生自 QObject 和 QPaintDevice 类,是所有用户界面对象的基类。 QDialog 和 QFrame 类也派生自 QWidget 类。它们有自己的子类系统。
QWidget class, derived from QObject and QPaintDevice classes is the base class for all user interface objects. QDialog and QFrame classes are also derived from QWidget class. They have their own sub-class system.
以下是一些常用的控件精选列表
Here is a select list of frequently used widgets
Sr.No. |
Widgets & Description |
1 |
QLabel Used to display text or image |
2 |
QLineEdit Allows the user to enter one line of text |
3 |
QTextEdit Allows the user to enter multi-line text |
4 |
QPushButton A command button to invoke action |
5 |
QRadioButton Enables to choose one from multiple options |
6 |
QCheckBox Enables choice of more than one options |
7 |
QSpinBox Enables to increase/decrease an integer value |
8 |
QScrollBar Enables to access contents of a widget beyond display aperture |
9 |
QSlider Enables to change the bound value linearly. |
10 |
QComboBox Provides a dropdown list of items to select from |
11 |
QMenuBar Horizontal bar holding QMenu objects |
12 |
QStatusBar Usually at bottom of QMainWindow, provides status information. |
13 |
QToolBar Usually at top of QMainWindow or floating. Contains action buttons |
14 |
QListView Provides a selectable list of items in ListMode or IconMode |
15 |
QPixmap Off-screen image representation for display on QLabel or QPushButton object |
16 |
QDialog Modal or modeless window which can return information to parent window |
典型的基于 GUI 的应用程序的顶级窗口由 QMainWindow 小部件对象创建。上面列出的一些小部件在这个主窗口中占据各自指定的位置,而其他一些小部件则使用各种布局管理器放置在中央小部件区域中。
A typical GUI based application’s top level window is created by QMainWindow widget object. Some widgets as listed above take their appointed place in this main window, while others are placed in the central widget area using various layout managers.
下图显示了 QMainWindow 框架 -
The following diagram shows the QMainWindow framework −
