I've created two uis using the Qt Designer, imported them into my script and set them in the normal way using the setupUi() method. When a button is clicked, and the appropriate method is executed, the new ui is loaded, but all of the widgets and connections from the old one persist.
What is the proper way to remove the connections and then delete all of the MainWindow's current children so that only the new ui's widgets and connections remain? Below is a simplified example of what I'm doing.
from PyQt4 import QtGui, QtCore
from Models import *
from Backward import Ui_Backward
from Forward import Ui_Forward
class MainWindow( QtGui.QMainWindow ):
def __init__( self ):
QtGui.QMainWindow.__init__( self, None )
self.move_forward()
def move_forward( self ):
self.ui = Ui_Forward()
self.ui.setupUi( self )
self.connect( self.ui.Button, QtCore.SIGNAL('clicked()'), self.move_backward )
def move_backward( self ):
self.ui = Ui_Backward()
self.ui.setupUi( self )
self.connect( self.ui.Button, QtCore.SIGNAL('clicked()'), self.move_forward )
Once Ui_Forward is set and the button is pressed, Ui_Backward is set correctly, but all of the widgets from Ui_Forward are still in the MainWindow's list of children.