Hello everyone. I have another problem with PyQT, this time I have an example that will be far more useful since it contains part of my code (defanged of course!) I have a hard time figuring out how to close the 'PROGRAM SELECT' dialog window by only using the 'LOGOUT' button. I could simply use the close button on the form, but I want to do it with the 'LOGOUT' button.

Could anyone help me solve this conundrum?

Here is some compilable code for you all to chew on.

Qt Code:
  1. connectionName = 'example'
  2.  
  3. class SelectProgramForm(QtGui.QDialog):
  4. def __init__(self, connName, connPrivilege):
  5. QtGui.QWidget.__init__(self)
  6. self.fooA = connName
  7. self.fooB = connPrivilege
  8.  
  9. self.widgetWidth = 100
  10. self.formWidth = self.widgetWidth + 40
  11.  
  12. def setupUi(self, programSelectForm):
  13. programSelectForm.setObjectName("programSelectForm")
  14. programSelectForm.resize(400, self.formWidth)
  15. self.widget = QtGui.QWidget(programSelectForm)
  16. self.widget.setGeometry(QtCore.QRect(20, 20, 360, self.widgetWidth))
  17. self.widget.setObjectName("widget")
  18. self.verticalLayout = QtGui.QVBoxLayout(self.widget)
  19. self.verticalLayout.setObjectName("verticalLayout")
  20. self.instructionLabel = QtGui.QLabel(self.widget)
  21. self.instructionLabel.setObjectName("instructionLabel")
  22. self.verticalLayout.addWidget(self.instructionLabel)
  23. spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
  24. self.verticalLayout.addItem(spacerItem)
  25. self.optionsGridLayout = QtGui.QGridLayout()
  26. self.optionsGridLayout.setObjectName("optionsGridLayout")
  27.  
  28.  
  29. self.verticalLayout.addLayout(self.optionsGridLayout)
  30. spacerItemUpper = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
  31. self.verticalLayout.addItem(spacerItemUpper)
  32. self.horizontalLayout = QtGui.QHBoxLayout()
  33. self.horizontalLayout.setObjectName("horizontalLayout")
  34. spacerItemLower = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
  35. self.horizontalLayout.addItem(spacerItemLower)
  36. self.pushButtonLogout = QtGui.QPushButton(self.widget)
  37. self.pushButtonLogout.setObjectName("pushButtonLogout")
  38. self.horizontalLayout.addWidget(self.pushButtonLogout)
  39. self.verticalLayout.addLayout(self.horizontalLayout)
  40.  
  41. self.connect(self.pushButtonLogout, QtCore.SIGNAL("clicked()"), self.reject)
  42.  
  43. self.retranslateUi(programSelectForm)
  44. QtCore.QMetaObject.connectSlotsByName(programSelectForm)
  45.  
  46.  
  47. def retranslateUi(self, programSelectForm):
  48. programSelectForm.setWindowTitle(QtGui.QApplication.translate("programSelectForm", "Program Select", None, QtGui.QApplication.UnicodeUTF8))
  49. self.instructionLabel.setText(QtGui.QApplication.translate("programSelectForm", "Select the program that you wish to access:", None, QtGui.QApplication.UnicodeUTF8))
  50. self.pushButtonLogout.setText(QtGui.QApplication.translate("programSelectForm", "Logout", None, QtGui.QApplication.UnicodeUTF8))
  51.  
  52.  
  53. class LoginForm(QtGui.QDialog):
  54. def __init__(self, connName):
  55. self.fooA = connName
  56.  
  57. def setupUi(self, LoginForm):
  58. LoginForm.setObjectName("LoginForm")
  59. LoginForm.resize(275, 175)
  60. self.widget = QtGui.QWidget(LoginForm)
  61. self.widget.setGeometry(QtCore.QRect(10, 10, 251, 147))
  62. self.widget.setObjectName("widget")
  63. self.verticalLayout = QtGui.QVBoxLayout(self.widget)
  64. self.verticalLayout.setObjectName("verticalLayout")
  65. self.dataInputLayout = QtGui.QHBoxLayout()
  66. self.dataInputLayout.setObjectName("dataInputLayout")
  67. self.labelVerticalLayout = QtGui.QVBoxLayout()
  68. self.labelVerticalLayout.setObjectName("labelVerticalLayout")
  69. self.userIDLabel = QtGui.QLabel(self.widget)
  70. self.userIDLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
  71. self.userIDLabel.setObjectName("userIDLabel")
  72. self.labelVerticalLayout.addWidget(self.userIDLabel)
  73. self.passwordLabel = QtGui.QLabel(self.widget)
  74. self.passwordLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
  75. self.passwordLabel.setObjectName("passwordLabel")
  76. self.labelVerticalLayout.addWidget(self.passwordLabel)
  77. self.dataInputLayout.addLayout(self.labelVerticalLayout)
  78. self.labelButtonVerticalLayout = QtGui.QVBoxLayout()
  79. self.labelButtonVerticalLayout.setObjectName("labelButtonVerticalLayout")
  80. self.userIDLineEdit = QtGui.QLineEdit(self.widget)
  81. self.userIDLineEdit.setObjectName("userIDLineEdit")
  82. self.labelButtonVerticalLayout.addWidget(self.userIDLineEdit)
  83. self.passwordLineEdit = QtGui.QLineEdit(self.widget)
  84. self.passwordLineEdit.setObjectName("passwordLineEdit")
  85. self.labelButtonVerticalLayout.addWidget(self.passwordLineEdit)
  86. self.dataInputLayout.addLayout(self.labelButtonVerticalLayout)
  87. self.verticalLayout.addLayout(self.dataInputLayout)
  88. spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
  89. self.verticalLayout.addItem(spacerItem)
  90. self.buttonLayout = QtGui.QHBoxLayout()
  91. self.buttonLayout.setObjectName("buttonLayout")
  92. self.newUserPushButton = QtGui.QPushButton(self.widget)
  93. self.newUserPushButton.setObjectName("newUserPushButton")
  94. self.buttonLayout.addWidget(self.newUserPushButton)
  95. self.loginPushButton = QtGui.QPushButton(self.widget)
  96. self.loginPushButton.setObjectName("loginPushButton")
  97. self.buttonLayout.addWidget(self.loginPushButton)
  98. self.verticalLayout.addLayout(self.buttonLayout)
  99.  
  100. self.retranslateUi(LoginForm)
  101. QtCore.QMetaObject.connectSlotsByName(LoginForm)
  102.  
  103. QtCore.QObject.connect(self.loginPushButton, QtCore.SIGNAL("clicked()"), self.confirmUser)
  104.  
  105. def confirmUser(self):
  106. programWindow = QtGui.QDialog()
  107. self.fooA = 'fooA' # these are needed in real program
  108. self.fooB = 'fooB' # these are needed in real program
  109. programDialog = SelectProgramForm(self.fooA, self.fooB)
  110. programDialog.setupUi(programWindow)
  111. programWindow.exec_()
  112.  
  113. def retranslateUi(self, LoginForm):
  114. LoginForm.setWindowTitle(QtGui.QApplication.translate("LoginForm", "Login", None, QtGui.QApplication.UnicodeUTF8))
  115. self.userIDLabel.setText(QtGui.QApplication.translate("LoginForm", "Username:", None, QtGui.QApplication.UnicodeUTF8))
  116. self.passwordLabel.setText(QtGui.QApplication.translate("LoginForm", "Password:", None, QtGui.QApplication.UnicodeUTF8))
  117. self.newUserPushButton.setText(QtGui.QApplication.translate("LoginForm", "New User?", None, QtGui.QApplication.UnicodeUTF8))
  118. self.loginPushButton.setText(QtGui.QApplication.translate("LoginForm", "Log In", None, QtGui.QApplication.UnicodeUTF8))
  119.  
  120.  
  121. if __name__ == '__main__':
  122. app = QtGui.QApplication(sys.argv)
  123. window = QtGui.QDialog()
  124. newUser = LoginForm(connectionName)
  125. newUser.setupUi(window)
  126. window.show()
  127. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 

Here is another compilable example that shows what I am looking for. Each window is able to close. Notice that there are three levels of windows, one activated by the other, that there are no close icons (aka 'X' buttons) on the second and third windows. If only this code would work with the other code...

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.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
  15. self.setGeometry(300, 300, 120, 150)
  16. self.setWindowTitle('LV3')
  17.  
  18. quit = QtGui.QPushButton('Close', self)
  19. quit.setGeometry(10, 10, 60, 35)
  20.  
  21. self.connect(quit, QtCore.SIGNAL('clicked()'),
  22. self.reject)
  23.  
  24.  
  25. class WindowLV2(QtGui.QDialog):
  26. def __init__(self):
  27. QtGui.QWidget.__init__(self)
  28. self.Window3 = WindowLV3()
  29.  
  30. self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
  31. self.setGeometry(300, 300, 120, 150)
  32. self.setWindowTitle('LV2')
  33.  
  34. self.quit = QtGui.QPushButton('Close', self)
  35. self.quit.setGeometry(10, 10, 60, 35)
  36.  
  37. next = QtGui.QPushButton('Lv3', self)
  38. next.setGeometry(10, 50, 60, 35)
  39.  
  40. self.connect(self.quit, QtCore.SIGNAL('clicked()'),
  41. self.reject)
  42.  
  43. self.connect(next, QtCore.SIGNAL('clicked()'),
  44. self.nextWindow)
  45.  
  46. def nextWindow(self):
  47. self.Window3.show()
  48.  
  49.  
  50. class WindowLV1(QtGui.QDialog):
  51. def __init__(self):
  52. QtGui.QWidget.__init__(self)
  53. self.Window2 = WindowLV2()
  54.  
  55. self.setGeometry(300, 300, 120, 150)
  56. self.setWindowTitle('LV1')
  57.  
  58. next = QtGui.QPushButton('Lv2', self)
  59. next.setGeometry(10, 50, 60, 35)
  60.  
  61. quit = QtGui.QPushButton('Close', self)
  62. quit.setGeometry(10, 10, 60, 35)
  63.  
  64. self.connect(next, QtCore.SIGNAL('clicked()'),
  65. self.nextWindow)
  66.  
  67. self.connect(quit, QtCore.SIGNAL('clicked()'),
  68. self.reject)
  69. #QtGui.qApp, QtCore.SLOT('quit()'))
  70.  
  71. def nextWindow(self):
  72. self.Window2.show()
  73.  
  74.  
  75. if __name__ == '__main__':
  76. app = QtGui.QApplication(sys.argv)
  77. Window1 = WindowLV1()
  78. Window1.show()
  79. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 

Happy hunting!