PyQt UI event control segregation

感情迁移 提交于 2019-12-25 17:55:32

问题


I am a beginner in python but my OOPS concept from Java and Android are strong enough to motivate me in making some tool in python. I am using PyQt for developing the application. In my application there are lot of QTabWidget used and has lot of UI controls in each TAB widget. Please see the screenshot for the same.

All of the event control of entire tool i have kept in one single file but now i want to segregate it based on one individual python file per QTab for event control inside the Tab.

My project file architecture looks like :

I know this would be some really easy thing but considering my experience with Python i am finding it difficult. I would really appreciate example with code snippet. Since i am able to control real complicated QThread from seperate files but not able get how to do it for Ui controls.

I tried making a file for it like i made for Thread classes but end up with argument passing expection to super

from generated.MainGUI import Ui_MainWindow
class SemiAuto_Create_Load(QtGui.QMainWindow):
    def __init__(self,parent=none):
        super(SemiAuto_Create_Load, self).__init__()
        self.ui = Ui_MainWindow
        self.ui.setupUi(self)
        self.connectControlEvents()

Tried : self.sacl = SemiAuto_Create_Load()

Exception :

TypeError: init() takes exactly 3 arguments (1 given)


回答1:


Okay i got this working with changes in

Mainwindow.py

class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent = None):
        super(MainWindow, self).__init__(parent)
        Profile().notify(None)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.connectButtons()

        SemiAuto_Create_Load(self, self.ui)

And

SemiAuto_Create_Load

class SemiAuto_Create_Load(QtGui.QMainWindow):
    def __init__(self, parent, ui):
        super(SemiAuto_Create_Load, self).__init__(parent)
        self.ui = ui
        self.connectControlEvents()

    def connectControlEvents(self):
        self.ui.load_vsa_radio.clicked.connect(self.onLoad_vsa_radio)
        self.ui.create_vsa_radio.clicked.connect(self.onCreate_vsa_radio)

Problem was passing the parameter with parent in init() and trying to get the object of MainGUI directly instead of as a parameter from MainWindow



来源:https://stackoverflow.com/questions/40926910/pyqt-ui-event-control-segregation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!