0

How to open a new window after the user clicks a button is described here:

https://stackoverflow.com/a/21414775/1898982

and here:

https://stackoverflow.com/a/13519181/1898982

class Form1(QtGui.QWidget, Ui_Form1):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.setupUi(self)
        self.button1.clicked.connect(self.handleButton)
        self.window2 = None

    def handleButton(self):
        if self.window2 is None:
            self.window2 = Form2(self)
        self.window2.show()

class Form2(QtGui.QWidget, Ui_Form2):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.setupUi(self)

I want to develop a GUI application that consists of several steps. Once the user clicks next, the current window closes and another window opens. Technically I can do this like it is described above: Each window opens a new one. After a few steps this is pretty much nested.

Is there a better way to do this?

I would like to have the control flow in my main. Something like this:

main()
   window1 = win2()
   window1.show()
   wait until button in window1 is clicked, then
   window1.close()

   window2 = win2()
   window2.show()
   wait until button in window2 is clicked, then
   window1.close()
   ....
Community
  • 1
  • 1
jonie83
  • 1,136
  • 2
  • 17
  • 28

2 Answers2

0

Qt provides special widget for such cases, which called QWidget. Look at it. It's also available in Qt4.

Yurij
  • 1,530
  • 16
  • 30
0

I would recommend to use QWizard or QStackedWidget class to perform this task. You can easily switch between widgets or windows using either of these two classes. Refer to QWizard and QStackedWidget docs.

qurban
  • 3,885
  • 24
  • 36