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

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

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

相关推荐
InJre1 小时前
QT widgets 窗口缩放,自适应窗口大小进行布局
开发语言·qt·ui
Lossya1 小时前
【自动化测试】UI自动化的分类、如何选择合适的自动化测试工具以及其中appium的设计理念、引擎和引擎如何工作
自动化测试·测试工具·ui·appium·自动化
充值内卷4 小时前
WPF入门教学四 WPF控件概述
windows·ui·wpf
Magnetic_h1 天前
【iOS】单例模式
笔记·学习·ui·ios·单例模式·objective-c
Calvin8808284 天前
Android Tools | 如何使用Draw.io助力Android开发:从UI设计到流程优化
android·ui·draw.io
Magnetic_h4 天前
【iOS】ViewController的生命周期
笔记·学习·ui·ios·objective-c
Magnetic_h4 天前
【iOS】present和push
笔记·学习·ui·ios·objective-c
加勒比海涛4 天前
Element UI:初步探索 Vue.js 的高效 UI 框架
前端·vue.js·ui
fruge4 天前
【UI】element ui table(表格)expand实现点击一行展开功能
前端·vue.js·ui
598866753@qq.com4 天前
URP 线性空间 ui资源制作规范
ui·unity