Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:26:47+00:00 2026-05-21T07:26:47+00:00

All in the question title, and my simplified code below. According to the docs:

  • 0

All in the question title, and my simplified code below.
According to the docs:
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdialog.html#done
on clicking Ok, it should close and indeed if I close it using the window close button, it fires the event:

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MyDialog(QDialog):    
    def __init__(self):
        QDialog.__init__(self)
        self.button_box = QDialogButtonBox(self)
        self.button_box.addButton(self.button_box.Ok)
        self.connect(self.button_box, SIGNAL('accepted()'), self.on_accept)
        layout = QVBoxLayout()
        layout.addWidget(self.button_box)
        #self.setAttribute(Qt.WA_DeleteOnClose)
        self.setLayout(layout)
        self.connect(self.button_box, SIGNAL('destroyed(QObject*)'), self.on_destroyed)

    def on_destroyed(self, *args):
        print("destroying dialog")

    def on_accept(self):
        print("accepting")
        self.done(1)

    def closeEvent(self, event):
        print("close")
        return QDialog.closeEvent(self, event)

#    def __del__(self):
#        QDialog.destroy(self)

my_app = QApplication([])
my_widget = MyDialog()
result = my_widget.exec_()
del my_widget
#my_widget.destroy()
if result == 1:
    print("result!")
else:
    print("other result:", result)
my_app.exec_()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:26:47+00:00Added an answer on May 21, 2026 at 7:26 am

    The answer came from http://www.riverbankcomputing.com/pipermail/pyqt/2011-April/029589.html
    with many thanks to Hans-Peter Jansen

    1. Don’t hook handler for destroyed signal onto the object being destroyed.(seems obvious in retrospect)

    2. QDialog.accept() does not fire closeEvent, even though it does get destroyed – bug or documentation is misleading IMHO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question title says it all really - a lot slower than VS2005, with a
First of all, I apologise for the vagueness of the question title and if
Actually my question is all in the title. Anyway: I have a class and
Question in the title. And what happens when all 3 of $_GET[foo] , $_POST[foo]
Well, question is in title. Is it possible at all? I can use css
Simple question, to repeat the title: Does closing the WinForms application stops all active
First of all, I have no idea if the title even reflects my question.
Pretty all in question... I'm looking for batch script, code or library which allows
First of all, I'd like to ask to correct my question title if something
The question title basically says it all. Is it possible in JPA/Hibernate to gracefully

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.