tags:

views:

22

answers:

1

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.

A: 

I'm trying to imagine what your goal is here. If you are trying to implement a wizard type application where the screen presents one set of controls and then switches to another screen with forward and backward buttons then you should try using a QStackedWidget.

A QStackedWidget will allow you to define one or more "pages" and switch between them. You design each page independently without (necessarily) having to move controls from one page to the next.

Arnold Spence
My application has several different views so I was trying to create an organized way to transition between them. It looks like QStackedWidget will work for my purposes with a little bit of editing, thank you.
Twernmilt