I have a code which consists of 3 classes
. The classes widget1
and widget2
inherit from QFrame
class and consists of several lineedit
and combobox
for the user to enter information.
So, what I want is: when the program is launched, it will firstly bring up the QMainWindow
class with widget1
set as the central widget
.
The widget1
has a Check function
which is connected to a button on it. The check button will check whether a condition is true based on the data entered by the user on the page.
If the condition is true. I want the widget2
to set it as central wiget
of MainWindow
to replace existing central widget
, the widget1
.
My question is, how do I set the widget2
as the central widget of existing MainWidnow
class instance?
This is the format of my code:
class widget1(QtGui.QFrame):
def __init__(self,parent = None):
......
......
def Check(self):
if (condition):
#set widget2 as 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_()