重新设计用户界面后,QtDesigner 更改将丢失 [英] QtDesigner changes will be lost after redesign User Interface

查看:43
本文介绍了重新设计用户界面后,QtDesigner 更改将丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Qt Designer 设计 GUI 以在 Python 中使用,在 Qt Designer 中设计我想要的 UI 后,将其转换为 Python 代码,然后我更改生成的代码以在我的 Python 代码中执行某些操作,但是如果我更改了使用 Qt Designer 将 UI 重新转换为 python 代码,我丢失了之前对代码所做的更改.

I'm using Qt Designer for design GUI to use in python, after designing my desired UI in Qt Designer, convert it to python code and then I changed generated code to do some action in my python code, but if I changed the UI with Qt Designer and convert it to python code again, I lost my previous changes on my code.

我该如何解决问题?

我们可以在python中将一个类扩展到多个文件中以在其他文件中编写代码吗?

can we Spreading a Class Over Multiple Files in python to write code in other files?

推荐答案

最简单的方法是在python代码中直接使用*.ui文件,不需要每次更改都转换为*.py文件你好你可以在你的项目中使用这个伪代码.

The easiest way is to use the *.ui file directly in the python code, you don't need convert to *.py file every time you change the ui. you can use this pseudo code in your project.

# imports
from PyQt5 import uic

# load ui file
baseUIClass, baseUIWidget = uic.loadUiType("MainGui.ui")

# use loaded ui file in the logic class
class Logic(baseUIWidget, baseUIClass):
    def __init__(self, parent=None):
        super(Logic, self).__init__(parent)
        self.setupUi(self)
         .
         .
         .
         .

def main():
    app = QtWidgets.QApplication(sys.argv)
    ui = Logic(None)
    ui.showMaximized()
    sys.exit(app.exec_())

这篇关于重新设计用户界面后,QtDesigner 更改将丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆