Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] closeEvent question

[SOLVED] closeEvent question

Scheduled Pinned Locked Moved General and Desktop
closeeventexec
3 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lukeQt
    wrote on 29 Jul 2015, 16:18 last edited by lukeQt
    #1

    Hi Everyone,

    I have a question with the closeEvent method. If I use self.accept() in the close event I get what I am expecting. If I use event.accept() the window did not execute. Why is event.accept() not working? See below for the example.

    After the second window closes I was expecting the print statement to print. Am I not understanding how exec_() works?

        class Tool1(QtGui.QDialog, ui_tool_1_1.Ui_tool1_1_Dialog):
            """Tool1 dialog"""
    
            # class Initialization
            def __init__(self, parent=None):
    
                # python super so script does not need to call the methods by name.
                super(Tool1, self).__init__(parent)
                self.setupUi(self)
    
                # Push button to open a new gui.
                self.add_evt_pushButton.clicked.connect(self.addEvt)
    
            def addEvt(self):
                test = AppField(parent=self)
                if test.exec_():
                    print"hello"
    
    
        class AppField(QtGui.QDialog, ui_app_field.Ui_AppFieldDialog):
             """
             Tool 2. 
             """
             # class Initialization
            def __init__(self, parent=None):
                super(AppField, self).__init__(parent)
                self.setupUi(self)
    
                # connection to okay button.
                self.ok_pushButton.clicked.connect(self.okay_button)
    
            def okay_button(self):
                """
                handles the ok push button.
                """
                self.close()
    
            def closeEvent(self, event):
                if QtGui.QMessageBox.question(self, "warning", "do you want to close",
                                         QtGui.QMessageBox.Yes|QtGui.QMessageBox.No) == QtGui.QMessageBox.No:
                    event.ignore()
                else:
                    event.accept()
    
    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      QT-static-prgm
      wrote on 29 Jul 2015, 17:44 last edited by
      #2

      Not sure about Phyton, but for c++ i'd use done(int) to exit the dialog.

      So if you have an dialog class myClass and you close it with done(1), myClass.exec() will return 1.

      I'm sure it will be simular for phyton. But i haven't understand the accept and ignore thing, so i cannot explain you why it does not work the way you want to do it

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lukeQt
        wrote on 30 Jul 2015, 19:31 last edited by lukeQt
        #3

        My understanding of self.close() got the better of me. self.close() returns self.reject(). That was what I did not understand. self.done(1) would also work, but I think self.accept() is clearer in this case.

        Thank you QT-static-prgm.

        1 Reply Last reply
        0

        3/3

        30 Jul 2015, 19:31

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved