Python将QtDesigner类作为动态参数传递给外部fi中的类

2024-06-16 12:29:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望能够在单独的*.py文件中的两个Python类之间传递任何QT类对象。我研究了这个网上和内,所以才张贴。我对OO或Python没有那么熟练

第一个py文件是在QT\u designer(5.11)中创建的:rs485ConfigMenu,类Ui\u rs485ConfigMenu(object),从PyQt5导入QtCore、QtGui、qtwidget。别碰那个密码

我用一个类编写了第二个python(python3.5)文件,该类应该接受Ui\u rs485ConfigMenu。我知道类的第二个参数是错误的,但我不知道如何根据需要为任何Ui对象传入Ui类(例如Ui\u menu01与Ui\u menu02等)

我为第二个单独的python文件及其类编写的代码是:

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
widgetList = [ "QPushButton", "QCheckBox", "QDialogButtonBox", "QLineEdit", "QRadioButton", "QComboBox", "QLabel"]

class widgetListMethod( QMainWindow, Ui_menu ):
    def __init__(self):
        super( widgetListMethod, self ).__init__()
#        Ui_mainMenu.__init__(self)
#        self.setupUi(self)

    def iterThroughWidgets(self):
        menuWidgets = {}
        i = 0

        b = self.mainMenuFrame.children()
        #need general menuFrame name for all menus
        #need way of checking all instances in widgetList

        for w in b:

            flag1 = 0
            string0 = str(type(w))
            string1 = string0.split("PyQt5.QtWidgets.")
            string2 = string1[1]
            string3 = string2.split("'")
            if not set(string3).isdisjoint(widgetList):

               widgetText = w.text()
               labelValue = widgetText.split("_value")

               if isinstance( w, QLabel ) and len( labelValue ) > 1:
                   #keep only those QLabels that have .value in label
                   i = i + 1
                   flag1 = 1
                elif not isinstance( w, QLabel ):
                  i = i + 1
                  flag1 = 1

                if flag1 == 1:
                  x = w.geometry().x()
                  y = w.geometry().y()
                  menuWidgets[i] = [x, y, widgetText, w ]
        return menuWidgets

仅来自QtDesigner的Ui代码就超过3000个字符的长度3000+。无法粘贴Ui和py代码。很高兴发送或提供安全网站的链接


Tags: 文件代码infrompyimportselfui