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

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

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

相关推荐
知识分享小能手21 小时前
uni-app 入门学习教程,从入门到精通,uni-app中uCharts组件学习((8)
vue.js·学习·ui·微信小程序·小程序·uni-app·echarts
Aevget1 天前
界面控件Kendo UI for Angular 2025 Q3亮点 - 全新的AI编码助手
ui·界面控件·kendo ui·ui开发·1024程序员节
油炸自行车2 天前
【Qt】VS Code配置Qt UI插件,vscode打开Qt Designer ,vscode打开Qt*.ui文件
qt·ui·cursor·qt designer·vscode插件·trae·qt ui
程序员小远2 天前
Appium+python+unittest搭建UI自动化框架
自动化测试·软件测试·python·测试工具·ui·appium·测试用例
尤老师FPGA3 天前
LVDS系列32:Xilinx 7系 ADC LVDS接口参考设计(三)
android·java·ui
瘦马3 天前
PhotoShop网页版为人像换背景,一键完成抠图换景
ui·photoshop
xingxing_F3 天前
Axure RP 11 for Mac 交互式原型设计软件
macos·ui·axure·photoshop
Larry_Yanan3 天前
QML学习笔记(四十六)QML与C++交互:Q_PROPERTY宏映射
c++·笔记·qt·学习·ui·交互
Larry_Yanan4 天前
QML学习笔记(四十四)QML与C++交互:对QML对象设置objectName
开发语言·c++·笔记·qt·学习·ui·交互
偶尔的鼠标人4 天前
Avalonia 的命令基类和通知基类备份
ui·mvvm·avalonia