当前位置:网站首页>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_())
边栏推荐
猜你喜欢

ROS2 Foxy depthai_ ROS tutorial

我选的热门专业,四年后成了“天坑”

Google Earth Engine(GEE)——全球人类居住区网格数据 1975-1990-2000-2014 (P2016)

Look at the sky at dawn and the clouds at dusk, and enjoy the beautiful pictures

Cs5268 advantages replace ag9321mcq typec multi in one docking station scheme

Redis exploration: cache breakdown, cache avalanche, cache penetration

游戏公会在去中心化游戏中的未来

JS discolored Lego building blocks

Feign & Eureka & zuul & hystrix process

波浪动画彩色五角星loader加载js特效
随机推荐
Global and Chinese styrene acrylic lotion polymer development trend and prospect scale prediction report Ⓒ 2022 ~ 2028
leetcode 322. Coin Change 零钱兑换(中等)
Machine learning - performance metrics
Introduction to reverse debugging PE structure input table output table 05/07
[development of large e-commerce projects] performance pressure test - basic concept of pressure test & jmeter-38
Investment analysis and prospect prediction report of global and Chinese p-nitrotoluene industry Ⓙ 2022 ~ 2027
Router. use() requires a middleware function but got a Object
流量管理技术
flinkcdc要实时抽取oracle,对oracle要配置什么东西?
Idea of [developing killer]
Scene function of wooden frame
Meta再放大招!VR新模型登CVPR Oral:像人一样「读」懂语音
Cs5268 advantages replace ag9321mcq typec multi in one docking station scheme
Yarn restart applications record recovery
R language builds a binary classification model based on H2O package: using H2O GBM build gradient hoist model GBM, use H2O AUC value of AUC calculation model
C language learning
Social distance (cow infection)
Redis exploration: cache breakdown, cache avalanche, cache penetration
Feign & Eureka & zuul & hystrix process
When Sqlalchemy deletes records with foreign key constraints, the foreign key constraints do not work. What is the solution?