当前位置: 首页 > news >正文

PyQt5 UI混合开发,控件的提升

  • PromoteLabelTest.py 提升的类
import sys
from PyQt5.QtWidgets import QApplication, QWidget,QVBoxLayout,QTextEdit,QPushButton,QHBoxLayout,QFileDialog,QLabelclass PromoteLabel(QLabel):def __init__(self,parent = None):super().__init__(parent)self.setText("111111")self.setStyleSheet("background-color:rgb(100,100,100);")
  • T.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>Form</class><widget class="QWidget" name="Form"><property name="geometry"><rect><x>0</x><y>0</y><width>520</width><height>431</height></rect></property><property name="windowTitle"><string>Form</string></property><widget class="PromoteLabel" name="label"><property name="geometry"><rect><x>70</x><y>120</y><width>111</width><height>61</height></rect></property><property name="text"><string/></property></widget><widget class="QPushButton" name="pushButton"><property name="geometry"><rect><x>260</x><y>200</y><width>75</width><height>23</height></rect></property><property name="text"><string>PushButton</string></property></widget></widget><customwidgets><customwidget><class>PromoteLabel</class><extends>QLabel</extends><header>PromoteLabelTest</header></customwidget></customwidgets><resources/><connections/>
</ui>
  • Ui_T.py   .ui生成的
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'c:\Users\481073\Desktop\new\test.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# 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, QtWidgetsclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(520, 431)self.label = PromoteLabel(Form)self.label.setGeometry(QtCore.QRect(70, 120, 111, 61))self.label.setText("")self.label.setObjectName("label")self.pushButton = QtWidgets.QPushButton(Form)self.pushButton.setGeometry(QtCore.QRect(260, 200, 75, 23))self.pushButton.setObjectName("pushButton")self.retranslateUi(Form)QtCore.QMetaObject.connectSlotsByName(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "Form"))self.pushButton.setText(_translate("Form", "PushButton"))
from PromoteLabelTest import PromoteLabel
  • Public_Ui_test.py    逻辑层
from Ui_T import *
from PyQt5.QtWidgets import QApplication, QWidget,QVBoxLayout,QTextEdit,QPushButton,QHBoxLayout
from PyQt5.QtWidgets import QLabelclass LogicalLabel(Ui_Form,QWidget):def __init__(self,parent = None):super().__init__(parent)self.initUI()def initUI(self):self.setupUi(self)self.label.setText("22222")
  • main.py   主函数
import sys
from PyQt5.QtWidgets import QApplication, QWidget,QVBoxLayout,QTextEdit,QPushButton,QHBoxLayout
from Public_Ui_T import *class Demo(QWidget):def __init__(self):super(Demo, self).__init__()self.initUI()def initUI(self):self.setWindowTitle("...")self.resize(1200, 600)Vlayout = QVBoxLayout()MyLabel = LogicalLabel()Vlayout.addWidget(MyLabel)self.setLayout(Vlayout)if __name__ == "__main__":app = QApplication(sys.argv)main = Demo()main.show()sys.exit(app.exec_())

 

  • 效果

7cc3f0cc88d74c059c7d7a2e46106a03.png

 

http://www.lryc.cn/news/516916.html

相关文章:

  • IP查询于访问控制保护你我安全
  • SpringBoot数据层解决方案
  • 前端数据模拟器 mockjs 和 fakerjs
  • Python 类 Class
  • PHP语言的并发编程
  • 小米智能哑铃上市,代理 IP 视角下的智能健身新篇
  • 业务日志设计
  • 对话|全年HUD前装将超330万台,疆程技术瞄准人机交互“第一屏”
  • 【论文笔记】QLoRA: Efficient Finetuning of Quantized LLMs
  • 计算机网络之---物理层的基本概念
  • Burpsuite20241102macM1版安装
  • 缓存常见问题
  • C++ 入门第25天:线程池(Thread Pool)基础
  • 微信小程序中的 storage(本地存储)和内存是两个完全不同的存储区域
  • WLAN基本原理与配置
  • KaliLinux 2022.1安装和相关配置
  • HarmonyOS开发:ArkTS初识
  • Unity的四种数据持久化方式
  • 机器学习笔记 - 单幅图像深度估计的最新技术
  • Postman接口测试02|接口用例设计
  • C#语言的学习路线
  • 双目的一些文章学习
  • 开源模型应用落地-qwen2-7b-instruct-LoRA微调合并-ms-swift-单机单卡-V100(十三)
  • 【C++面向对象——类与对象】CPU类(头歌实践教学平台习题)【合集】
  • 性能测试05|JMeter:分布式、报告、并发数计算、性能监控
  • 关于Java面试题大全网站无法访问的解决方案
  • CSS进阶和SASS
  • SwiftUI 撸码常见错误 2 例漫谈
  • JavaScript系列(9)-- Set数据结构专题
  • 开发培训-慧集通(iPaaS)集成平台脚本开发Groovy基础培训视频