PDA

View Full Version : Multi-dialog program in PyQT will not close



Danny Hatt
18th June 2010, 21:36
For my project, I require multiple widgets to be linked to each other. One button would go from one level, another button would go down two levels. To get a basic idea of what I'm looking for without showing all my code, here is a compilable example:



'''
Created on 2010-06-18

@author: dhatt
'''

import sys
from PyQt4 import QtGui, QtCore

class WindowLV3(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)

self.setGeometry(300, 300, 120, 150)
self.setWindowTitle('LV3')

quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)

self.connect(quit, QtCore.SIGNAL('clicked()'),
QtGui.qApp, QtCore.SLOT('quit()')) # this doesn't work


class WindowLV2(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.Window3 = WindowLV3()

self.setGeometry(300, 300, 120, 150)
self.setWindowTitle('LV2')

quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)

next = QtGui.QPushButton('Lv3', self)
next.setGeometry(10, 50, 60, 35)

self.connect(quit, QtCore.SIGNAL('clicked()'),
QtGui.qApp, QtCore.SLOT('reject()')) # this doesn't work

self.connect(next, QtCore.SIGNAL('clicked()'),
self.nextWindow)

def nextWindow(self):
self.Window3.show()


class WindowLV1(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.Window2 = WindowLV2()

self.setGeometry(300, 300, 120, 150)
self.setWindowTitle('LV1')

next = QtGui.QPushButton('Lv2', self)
next.setGeometry(10, 50, 60, 35)

quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)

self.connect(next, QtCore.SIGNAL('clicked()'),
self.nextWindow)

def nextWindow(self):
self.Window2.show()

self.connect(quit, QtCore.SIGNAL('clicked()'),
QtGui.qApp, QtCore.SLOT('reject()')) # this doesn't work


if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
Window1 = WindowLV1()
Window1.show()
sys.exit(app.exec_())


The problem is that I cannot close from a window and show the previous window. For example, if I clicked 'CLOSE' from inside from a LV3 window, it will transfer control back to a LV2 window.

What am I doing wrong?

ksorensen
21st November 2010, 22:12
I am not sure about how it should work.
But here are some things I noticed.

quit and next should be local in LV2 and LV3 - change to self.quit and self.next

QApplication does not have reject(). I changed it to quit() in LV1

And finally, self.connect for quit in LV1 is defined inside nextWindow. Should be moved up before nextWindow.

I have attached the code. Changed geometry settings to windows don't overlap - easier to see.5513