In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the comparative analysis of pyqt5 and qtdesigner in Python. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
I. understanding of the generation of empty programs
1. The GUI program is written by manual pure code.
two。 Qtdesigner is used to plan the interface.
Observe the differences between pyqt5 programs made in two different forms.
Understand that Qwidget is the base class based on all controls, including form controls, buttons, text, and so on.
Second, Qt Designer designer interface related properties
Geometry attribute:
X: indicates that the position where the form appears is 0 horizontally in the upper left corner of the screen
Y: indicates that the position where the form appears is 0 in the vertical direction of the upper left corner of the screen
Default width: 400
Default height: 300
ObjectName property: represents the name of the form object. The method setObjectName for setting the name of the form in the corresponding python code
Note: a form object is actually an instantiated object of qwidget
Third, supplementary pyuic command parsing
Use the Python.exe interpreter
-m PyQt5.uic.pyuic $FileName$-o $FileNameWithoutExtension$.py
Command description:-m means to call a module, this table indicates that the PyQt5.uic.pyuic module is called
$FileName$ indicates the name of the source file to be converted
-o indicates that the target file needs to be generated, here $FileNameWithoutExtension$ is used to represent the target file with the same file name as the source file but does not contain the extension, the extension, we connect .py by ourselves, then the final result is a file of type python.
IV. Understanding of signals in Qt
For example, a click event, a timeout signal, etc., are all signals in qt, which, in the final analysis, is an event that occurs on the interface.
Description of related path concepts
Absolute path: detailed path starting from the root directory
Relative path: the path relative to a file directory
Relative paths often have symbols that represent:
. The point represents the current path
.. Dots represent the upper path.
Fifth, supplementary explanation of function
Resize function
Function: resize the form.
There are two parameters, the first parameter represents the width value and the second parameter represents the height value.
For example:
Form.resize (400,300)
Move function
Function: adjust the position of the form.
The first parameter represents the horizontal position.
The second parameter represents the position in the vertical direction.
Examples of use:
Form.move (0Pol 0)
Show function
The show function of Pyqt5 is the display function of the form.
VI. Summary and emphasis
1. Master the corresponding relationship between qtdesigner design interface and pyuic converted file code.
two。 Master the basic usage of functions commonly used in the interface in pyqt5
3. Master the idea of how to call the generation interface. In fact, it is the key to how to use pyqt5 pure code to write gui interface.
The following is the source code for this section
The code after UI is converted to py:
#-*-coding: utf-8-*-
# Form implementation generated from reading ui file 'ljytest003.ui'## Created by: PyQt5 UI code generator 5.13.1 WARNING! All changes made in this file will be lost!
From PyQt5 import QtCore, QtGui, QtWidgets
Class Ui_Form (object): def setupUi (self, Form): Form.setObjectName ("Form") Form.resize (400,300) Form.move (0mem0) self.retranslateUi (Form) QtCore.QMetaObject.connectSlotsByName (Form)
Def retranslateUi (self, Form): _ translate = QtCore.QCoreApplication.translate Form.setWindowTitle (_ translate ("Form", "Form"))
Ljy003.py calls UI interface
# Import python system class library import sys# import the class library used by Pyqt5, QApplication application class, the base class of QWidget control from PyQt5.QtWidgets import QApplication,QWidget# import the module of the generated interface class import ljytest003# instantiates a class The application parameter print (sys.argv) # passed in to python through the constructor prints out a list of the absolute path names of the current file app=QApplication (sys.argv) # instantiates the interface base class w=QWidget () # instantiates the generated interface class form=ljytest003.Ui_Form () # loads the generated form control and configuration into the w control object form.setupUi (w) # form display w.show () # app.exec_ ( Represents the beginning of the program interface listening event It's an endless cycle. Sys.exit (app.exec_ ())
This is the end of the comparative analysis of pyqt5 and qtdesigner in Python. I hope the above content can be helpful to you and 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.