ui转为py文件后,调用方法

一.zhongke.py

python 复制代码
from PyQt5 import QtCore, QtGui, QtWidgets

from poseUI import Ui_Form
import sys
class ZhongKe(QtWidgets.QMainWindow, Ui_Form):
    def __init__(self):
        super(ZhongKe,self).__init__()
        self.setupUi(self)
if __name__ == '__main__':

    from PyQt5 import QtCore
    # QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)  # 自适应分辨率
    app = QtWidgets.QApplication(sys.argv)
    ui = ZhongKe()
    ui.show()
    sys.exit(app.exec_())

二. poseUi.py(pose.ui------>poseUi.py)

命令端输入 pyuic5 -o poseUi.py pose.ui

python 复制代码
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1164, 836)
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(650, 470, 75, 24))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(Form)
        self.pushButton_2.setGeometry(QtCore.QRect(530, 470, 75, 24))
        self.pushButton_2.setObjectName("pushButton_2")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "PushButton"))

三. ui无法调用鼠标事件解决办法

这是导入ui文件的方式不对

python 复制代码
from PyQt5 import QtWidgets, uic
import sys
 
form_class = uic.loadUiType('new.ui')[0]
class Ui(QtWidgets.QMainWindow, form_class):
    def __init__(self):
        super(Ui, self).__init__()
        self.setupUi(self)
 
 if __name__=='__main__':
	app = QtWidgets.QApplication(sys.argv)
	window = Ui()
	window.show()
	sys.exit(app.exec_())

四.调用成功后界面显示不全

可能是因为加了分页,取消即可

相关推荐
码匠许师傅2 天前
【设计模式精讲】25.状态模式(State)
c++·ui·设计模式·状态模式·uml
插件开发2 天前
Illustrator 插件开发:链接文件存在检查的原理与实战
ui·illustrator
xy34532 天前
axure9.0 如何打造一个计时器(简单版)
前端·ui·html·axure·原型·产品设计
图扑软件3 天前
下篇・换墨|主题/多语言/移动端,一套组件全覆盖
前端·javascript·ui·性能优化·数据可视化
object not found4 天前
从 Page Design 到 System Design:我对 UI/UX 的一次认知变化
ui·ux
xy34534 天前
Axure9.0中继器遮罩实现方法
前端·ui·html·axure·原型·产品设计
晴天164 天前
Ant Design UI 库核心原理与应用
ui
玫瑰互动GEO5 天前
腾讯AnswerBit(GEO优化监测平台)技术拆解:UI自动化如何采集真实AI回答
大数据·人工智能·ui·ai·自动化·geo优化
摸鱼仙人~5 天前
Qwen-Code ACP与AG-UI协议深度解析:区别、场景与实战报文对比
ui
图扑软件5 天前
中篇・运笔|统一 DataModel 底座,HT UI 组件万物同源
javascript·低代码·ui·性能优化·数据可视化