对于我的项目,我需要多个对话框相互链接。一个按钮将进入一级,另一个按钮将返回两级。为了在不显示所有代码的情况下大致了解我正在寻找的内容,这是一个可编译的示例:
'''
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 will close entire program
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_())
问题是我无法从窗口关闭并显示上一个窗口。例如,如果我从 LV3 窗口中单击“关闭”按钮,它会将控制权转移回 LV2 窗口。我可以调用 QtCore.SLOT('quit()')),但它会关闭整个程序,我不希望这样。
我在这里做错了什么?