当前位置:网站首页>Qtdeisgner, pyuic detailed use tutorial interface and function logic separation (nanny teaching)
Qtdeisgner, pyuic detailed use tutorial interface and function logic separation (nanny teaching)
2022-07-01 13:16:00 【Opencv+pyqt Xiaobai】
About QtDesigner Sure pip It's fine too GitHub Download the third-party version
QtDesigner Third party plug-in version https://github.com/PyQt5/QtDesigner/releases
Can generate directly PyQt Code , Omit PyUic
Video teaching QtDesigner course - Interface and function logic are separated - Modify the layout in real time _ Bili, Bili _bilibili

Start by opening QtDesigner Generate a good window , Then save the file
Here is the rest of video teaching

open PyCharm find Ui File by PyUic Turn into Py file
QtDesigner Plug in version internal It also supports direct copying of code , Just create a new file and paste it
This step is Ui Document conversion Py Just a file
Import what you need
import PyQt5
from PyQt5.QtWidgets import QMainWindow
from untitled import Ui_FormAnd then create a new one Py file , Define a class inheritance inside QMainWindow And your layout class ( open UI The conversion Py You can see the class name in the file )
class MyGui(QMainWindow,Ui_Form):Then define in the class
def __init__(self):
super().__init__()
self.setupUi(self)This initializes your window layout
Then write your main entrance at the end
while True
perhaps
if __name__ == '__main__':
You can not even write
The second way of writing is recommended
import sys
app = PyQt5.QtWidgets.QApplication(sys.argv)
MyUiStart = MyGui()
MyUiStart.show()# ui It will show
sys.exit(app.exec_())Then the main process is loaded. You can understand that this program has been repeating in the window layout
here MyGui Is the class name you defined
Finally, your interface will be displayed , And realize logical separation
To update the layout, just use QtDesigner open Ui Then modify the contents of the file to overwrite the original layout code
Complete code
Layout code
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1100, 857)
self.textBrowser = QtWidgets.QTextBrowser(Form)
self.textBrowser.setGeometry(QtCore.QRect(230, 210, 651, 201))
self.textBrowser.setObjectName("textBrowser")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.textBrowser.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'SimSun\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:48pt; font-weight:600; font-style:italic;\">Hi My Firends</span></p></body></html>"))
Main program code
# First, import the layout class
import PyQt5
from PyQt5.QtWidgets import QMainWindow
from untitled import Ui_Form
# In this way, you can inherit this window
# These two windows must inherit
class MyGui(QMainWindow,Ui_Form):
# Initialize window
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == '__main__':
import sys
app = PyQt5.QtWidgets.QApplication(sys.argv)
MyUiStart = MyGui()
MyUiStart.show()# ui It will show
sys.exit(app.exec_())
边栏推荐
- Feign & Eureka & zuul & hystrix process
- 请问flink mysql cdc 全量读取mysql某个表数据,对原始的mysql数据库有影响吗
- Application of 5g industrial gateway in scientific and technological overload control; off-site joint law enforcement for over limit, overweight and overspeed
- 声明一个抽象类Vehicle,它包含私有变量numOfWheels和公共函数Vehicle(int)、Horn()、setNumOfWheels(int)和getNumOfWheels()。子类Mot
- shell脚本导入存储过程到数据库
- R language uses conf of yardstick package_ The mat function calculates the confusion matrix of the multiclass model on each fold of each cross validation (or resampling), and uses the summary to outpu
- La taille de la pile spécifiée est petite, spécifiée à la sortie 328k
- SSO and JWT good article sorting
- PG基础篇--逻辑结构管理(触发器)
- Localtime can't re-enter. It's a pit
猜你喜欢
随机推荐
Vs code setting Click to open a new file window without overwriting the previous window
VM虚拟机配置动态ip和静态ip访问
Nexus builds NPM dependent private database
Wave animation color five pointed star loader loading JS special effects
游戏公会在去中心化游戏中的未来
A Fletter version of Notepad
Introduction to reverse debugging PE structure input table output table 05/07
SSO and JWT good article sorting
Class initialization and instantiation
PG basics -- Logical Structure Management (trigger)
When Sqlalchemy deletes records with foreign key constraints, the foreign key constraints do not work. What is the solution?
PG基础篇--逻辑结构管理(触发器)
学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......
Update a piece of data from the database. Will CDC get two pieces of data with OP fields D and C at the same time? I remember before, only OP was U
VM virtual machine configuration dynamic IP and static IP access
Shell script imports stored procedures into the database
MySQL gap lock
Yarn重启applications记录恢复
Jenkins+webhooks- multi branch parametric construction-
China NdYAG crystal market research conclusion and development strategy proposal report Ⓥ 2022 ~ 2028







