First off, I'm a complete newbie to PyQt.
I am trying to associate a function with the close button of the main window (red x in the corner of the window), but I have not succeeded. Right now, my code looks something like this:
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
def setupUi(self, MainWindow):
def retranslateUi(self, MainWindow):
def closeEvent(self, event):
print "User has clicked the red x on the main window"
In a separate "main" file, I have the following:
class GUIForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.threadData()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = GUIForm()
myapp.show()
ret = app.exec_()
sys.exit(ret)
However, when I run through the command line, I cannot see the print statement when I hit red x. I know that I am new to Qt, but I have seen many people ask this question, and none of the answers go beyond what is already written above.
One of these answers:
Answer # 1
Answer # 2
Both of these solutions are similar to mine, but they still do not work.
, , , , PyQt , . "Red X box", PyQt? , ?