Results 1 to 2 of 2

Thread: Multi-dialog program in PyQT will not close

  1. #1
    Join Date
    Jun 2010
    Posts
    5
    Qt products
    Platforms
    Unix/X11 Windows

    Default Multi-dialog program in PyQT will not close

    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:

    Qt Code:
    1. '''
    2. Created on 2010-06-18
    3.  
    4. @author: dhatt
    5. '''
    6.  
    7. import sys
    8. from PyQt4 import QtGui, QtCore
    9.  
    10. class WindowLV3(QtGui.QDialog):
    11. def __init__(self, parent=None):
    12. QtGui.QWidget.__init__(self, parent)
    13.  
    14. self.setGeometry(300, 300, 120, 150)
    15. self.setWindowTitle('LV3')
    16.  
    17. quit = QtGui.QPushButton('Close', self)
    18. quit.setGeometry(10, 10, 60, 35)
    19.  
    20. self.connect(quit, QtCore.SIGNAL('clicked()'),
    21. QtGui.qApp, QtCore.SLOT('quit()')) # this doesn't work
    22.  
    23.  
    24. class WindowLV2(QtGui.QDialog):
    25. def __init__(self, parent=None):
    26. QtGui.QWidget.__init__(self, parent)
    27. self.Window3 = WindowLV3()
    28.  
    29. self.setGeometry(300, 300, 120, 150)
    30. self.setWindowTitle('LV2')
    31.  
    32. quit = QtGui.QPushButton('Close', self)
    33. quit.setGeometry(10, 10, 60, 35)
    34.  
    35. next = QtGui.QPushButton('Lv3', self)
    36. next.setGeometry(10, 50, 60, 35)
    37.  
    38. self.connect(quit, QtCore.SIGNAL('clicked()'),
    39. QtGui.qApp, QtCore.SLOT('reject()')) # this doesn't work
    40.  
    41. self.connect(next, QtCore.SIGNAL('clicked()'),
    42. self.nextWindow)
    43.  
    44. def nextWindow(self):
    45. self.Window3.show()
    46.  
    47.  
    48. class WindowLV1(QtGui.QDialog):
    49. def __init__(self, parent=None):
    50. QtGui.QWidget.__init__(self, parent)
    51. self.Window2 = WindowLV2()
    52.  
    53. self.setGeometry(300, 300, 120, 150)
    54. self.setWindowTitle('LV1')
    55.  
    56. next = QtGui.QPushButton('Lv2', self)
    57. next.setGeometry(10, 50, 60, 35)
    58.  
    59. quit = QtGui.QPushButton('Close', self)
    60. quit.setGeometry(10, 10, 60, 35)
    61.  
    62. self.connect(next, QtCore.SIGNAL('clicked()'),
    63. self.nextWindow)
    64.  
    65. def nextWindow(self):
    66. self.Window2.show()
    67.  
    68. self.connect(quit, QtCore.SIGNAL('clicked()'),
    69. QtGui.qApp, QtCore.SLOT('reject()')) # this doesn't work
    70.  
    71.  
    72. if __name__ == '__main__':
    73. app = QtGui.QApplication(sys.argv)
    74. Window1 = WindowLV1()
    75. Window1.show()
    76. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by Danny Hatt; 18th June 2010 at 22:12. Reason: Typos, copilable code closer to to my problems

  2. #2
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multi-dialog program in PyQT will not close

    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.multiwin.py

Similar Threads

  1. Replies: 3
    Last Post: 17th December 2010, 02:06
  2. QT Modal Dialog
    By jiapei100 in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2010, 17:15
  3. Modal dialog not behaving
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 16th September 2008, 22:03
  4. Special Modal Dialog
    By adonel in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 08:12
  5. System modal dialog!!
    By boss_bhat in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2006, 07:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.