In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to understand the module structure of Qt For Python. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
After installing PyQt5/PySide2, we didn't rush to start programming the Python graphical interface. Because right now we don't know anything about PyQt5 and PySide2.
PyQt5 and PySide2 are the Python encapsulation modules of the QT graphical interface development kit, which maximize the use of the Python programming language to restore the functions and definitions of QT under the native C++. Therefore, we can complete the graphical interface application development of QT in Python programming language by using PyQt5 or PySide2.
At the same time, due to the differences in development history and licensing agreements between PyQt5 and PySide2, we recommend that you make the following choices between them:
If you just want to quickly learn graphical interface programming in Python or develop open source, non-commercial graphical interface applications, then it is recommended that you choose PyQt5
If the graphical interface application developed may be used for commercial purposes in the future, it is recommended that you use PyQt5 for development, then convert it into PySide2 code, and finally package it.
PySide2 with the strong support of Qt officials, all aspects have become more and more perfect, you can try to fully use PySide2.
So in the series of tutorials of "Python graphical interface programming that you can understand at a glance", in order to facilitate the demonstration, we use PyQt5 to explain the sample code of knowledge points. If readers have a need for PySide2 code, you can replace it yourself.
For most sub-modules, you only need to simply replace the PyQt5 in the module with PySide2, and other special modules can be described on the official website.
Before starting to use PyQt5/PySide2 for Python graphical interface programming, let's take a look at the structure of some of the graphical interface development modules we are going to use. Just like before decorating the house, only when we have an understanding of the structure and composition of the house, can we carry out better construction.
As a large module, unlike some small modules with only a small number of subclasses and method properties, PyQt5/PySide2 has a large number of submodules, definitions and objects. If you do not have an understanding of its global structure, you will fall into a dilemma of not knowing where to start.
First, the sub-module of PyQt5/PySide2
After installing PyQt5/PySide2, we can use from in IDE or code editor. Import... Or directly introduced and used by import.
To introduce PyQt5/PySide2 in IDE using from syntax, the code is as follows:
From PyQt5 import Q
If the IDE or code editor you are using has a smart prompt, the sub-modules that begin with Q under the PyQt5 module will be displayed, as shown in the following figure:
Because the style of the QT module is that the submodules begin with Q, the submodules shown in the IDE IntelliSense basically contain all the submodules in PyQt5.
These submodules include, but are not limited to, the following:
Among these modules, QtCore,QtWidgets,QtGui,QAxContainer,QtBluetooth,QtDBus,QtDesigner,QtHelp,QtLocation,QtMultimedia,QtMultimediaWidgets,QtNetwork,QtNetworkAuth,QtNfc,QtOpenGL,QtPositioning,QtPrintSupport,QtQml,QtQuick,QtQuickWidgets,QtRemoteObjects,QtSensors,QtSerialPort,QtSql,QtSvg,QtTest,QtWebChannel,QtWebSockets,QtWinExtras,QtXml,QtXmlPatterns can be roughly divided into the following categories:
Basic modules, which are universal and core, are useful modules for most QT applications
QT function module, which is used for specific purpose and function development.
QT tool module, which belongs to the tools provided by QT to improve the efficiency of graphical interface development.
Let's take a look at several types of modules.
Second, the general basic module-- the cornerstone of the house
In the general basic module of PyQt5, it is divided into core basic module and general basic module. In fact, it is easy to understand that the core foundation module is equivalent to the foundation, load-bearing beam, cement brick and so on of a house, which is used to build the basic structure of the house.
The submodules that belong to the base module have the following modules:
QtCore: this is the core non-graphical class used by other modules in PyQt5. This module is like the foundation and steel bar for building a house, providing core and powerful support for robust graphical interface programs, such as threading (QThread, QThreadPool), animation (QAbstractAnimation), event response (pyqtSignal, pyqtSlot, QEvent), input / output objects (QSettings, QFileinfo) and so on. A graphical interface program written in PyQt5 can not use the QtCore module, but a powerful graphical interface program written by PyQt5 will certainly use the QtCore module.
QtGui: this is the base class of graphical user interface components in PyQt5. It provides subclasses for graphics window integration, graphics event processing, 2D graphics images, fonts, and text. There are subclasses such as graphic drag and drop (QDrag, QDropEvent), image display (QBitmap, QImage), font definition (QFont), color definition (QColor), brush (QPen), and so on, similar to the wall construction when building a house.
QtWidget: this is the control module that extends the QtGui module in PyQt5. The so-called control module is that it provides a large number of controls and their layout classes. This is equivalent to the living room, kitchen, balcony, bedroom, and all kinds of furniture, furnishings, electrical appliances, equipment and so on. We will use a large number of QtWidget subclasses in the graphical interface programming process, such as window, button, input box, text box, selection box, layout and so on. Just like building a house, we can build a simple cabin out of planks and QtWidget without QtCore or QtGui.
The above three sub-modules are the core modules involved in the traditional graphical interface programming in PyQt5.
Note: we know that native Qt uses C++ language for graphical interface development. Since Qt4.7, Qt has introduced a new graphical interface development language-QML as a substitute for the native QT development language C++, and built a set of class libraries called QtQuick for building highly dynamic graphical applications using custom graphical interfaces.
It belongs to another branch of Qt development, and Qt's Python package also includes related module support, but in this series of tutorials, we only use modules developed by traditional Qt graphical interfaces.
Let's take a look at the functional modules.
Third, the functional module-- expanding the properties of the house
In the functional module, it is also divided into basic functional modules and other functional modules.
The importance of the basic functional module is lower than that of the core basic module, but higher than that of other functional modules. With the development of the times and the change of demand, a functional module may be upgraded to the basic functional module, or it may be downgraded to other functional modules. By the same token, an other functional module may also become a basic functional module.
Just like a few decades ago, every household connected to electricity is a goal, the network is only the configuration of the family. Now, every household has electricity, and the network has become standard.
In the current version, the basic functional module includes the following modules:
QtMultimedia: a multimedia module that provides support for audio, video, radio broadcast and camera functions
QtMultimediaWidgets: a control module for implementing multimedia functions, providing additional control support for designing video and cameras, which extends the functions of QtMultimedia and QtWidget modules
The above two function modules are used to realize the multimedia function.
QtNetwork: a module used to realize network programming, which makes it more convenient to do network programming in Qt graphical interface
QtSQL: a module for manipulating databases using SQL in Qt
QtTest: a module for unit testing of Qt graphical interface programs
As we said above, basic functional modules and other functional modules, like electricity and network, have different importance in different periods.
Regardless of the geometry of the changes, these modules are ultimately created to expand the functions of graphical interface programs. Let's take a look at some of the other functional modules in PyQt5:
QtNfc: this module provides access to near field communication (NFC) hardware
QtWebEngine: this module uses the open source Chromium browser project to embed Web browsing capabilities in graphical interface applications
QtWebSocket: this module provides WebSocket communication capabilities for graphical interface programs
QtSvg: this module provides functions for displaying the contents of SVG files
The subdivision of functional modules does not need to be particularly rigorous, because to some extent, modules except the core modules belong to functional modules. The core module is used to lay the foundation of the graphical interface program, and the functional module, whether it is the basic function or other functions, is used to realize the function of the graphical interface program. a module defined as other functional modules is used more frequently and more important than a basic functional module in its own graphical interface programming process. So we can use it flexibly.
IV. Tool module
The tool module of Qt is mainly to facilitate developers to design and develop graphical interface programs. It provides Qt designer (QtDesigner), a graphical programming tool, which can easily use mouse drag to quickly draw the interface of the program and the basic event response.
In order to facilitate your understanding of the code of each module of PyQt5, this series of tutorials will not use Qt designers to design and draw graphical interfaces. Readers who need it can download, install and use QT designers.
On how to understand the module structure of Qt For Python is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.