class - How to set the central widget of existing MainWidnow in Python PyQt4? -
i have code consists of 3 classes
. classes widget1
, widget2
inherit qframe
class , consists of several lineedit
, combobox
user enter information.
so, want is: when program launched, firstly bring qmainwindow
class widget1
set central widget
.
the widget1
has check function
connected button on it. check button check whether condition true based on data entered user on page.
if condition true. want widget2
set central wiget
of mainwindow
replace existing central widget
, widget1
.
my question is, how set widget2
central widget of existing mainwidnow
class instance?
this format of code:
class widget1(qtgui.qframe): def __init__(self,parent = none): ...... ...... def check(self): if (condition): #set widget2 central widget on mainwindow class widget2(qtgui.qframe): def __int__(self,parent = none): ..... ..... class mainwindow(qtgui.qmainwindow): def __init__(self,parent = none): qtgui.qmainwindow.__init__(self,parent) .... mywidgetone = widget1() self.setcentralwidget(mywidgetone) if __name__ == '__main__': app = qtgui.qapplicaiton(sys.argv) main = mainwindow() main.show() app.exec_()
i'd following mainwindow
:
class mainwindow(qtgui.qmainwindow): def __init__(self,parent = none): qtgui.qmainwindow.__init__(self,parent) .... self.setmycentral(widget1) def setmycentral(self, widgetclass): mywidget = widgetclass(self) self.setcentralwidget(mywidget)
and then, in widget1
:
def check(self): if (condition): self.parent().setmycentral(widget2)
now, please, follow conventions: classes start in capital letters (widget1
, widget2
) , methods don't (check
instead of check
)
Comments
Post a Comment