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_())

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

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

相关推荐
汉得数字平台1 小时前
【汉得飞码】构建接口与UI自动化测试全链路,让验证反馈持续驱动交付
自动化测试·人工智能·ui
兰亭妙微UI设计公司1 天前
兰亭妙微设计洞察:跳出界面视角,深度理解广义的全链路用户体验
ui·交互·ux
zhongben_keji1 天前
APP 本地数据与持久化体系全解:存储选型、SQLite WAL、数据库迁移与隐私清理
ui·ci/cd·自动化
loulanyue_1 天前
AI智能体24小时复刻Photoshop:什么该交给Agent、什么必须留给人——读Brandon Thomas演讲实录
人工智能·ui·rust·ai编程·photoshop
xy34532 天前
Axure 9.0 垂直菜单核心交互实战用法
ui·产品经理·axure·原型·原型设计
敲上瘾2 天前
Qt 主窗口QMainWindow:菜单栏、工具栏、状态栏与浮动窗口等
开发语言·c++·qt·ui·qt6.3
xy34533 天前
Axure 9.0 树元件介绍
ui·产品经理·axure·原型·原型设计
鲸渔6 天前
【AI Agent系列课程33-FastAPI 基础07】自动文档与接口调试:Swagger UI 和 ReDoc 入门
python·ui·fastapi·ai编程
敲上瘾10 天前
Qt控件通用属性:geometry、qrc资源到QSS样式表等
开发语言·c++·qt·ui
zdr尽职尽责14 天前
UnityCli 兼容2022版本
ui·unity·ai·c#·游戏引擎