[Qt-interest] QDialog::closeEvent() is called only when a modal dialog is closed by clicking the "X" button

Constantin Makshin cmakshin at gmail.com
Tue Jun 28 16:35:08 CEST 2011


Well, after paying a bit more attention to QDialog documentation I've found that accept() and reject() slots *hide* the dialog instead of closing it. But these slots' "friend" — the done() slot — *closes* the dialog (according to the documentation). So the behavior still looks weird as IMHO one would expect that accept() and reject() are simply convenience wrappers around done() and therefore the dialog should be closed, not just hidden...

As a workaround, I've used the event() function and put the parameter saving code into the "if (event->type() == QEvent::Close || event()->type() == QEvent::Hide)" block. But I'd appreciate more detailed information about QDialog's "close vs. hide" question.

On Tuesday, June 28, 2011 06:08:07 PM Zeljko wrote:
> Constantin Makshin wrote:
> 
> > Hello!
> > 
> > I want to save some modal dialog's parameters when it's closed and restore
> > them when it's created/opened again. The obvious way is to save parameters
> > inside the closeEvent() function and restore inside the constructor. This
> > approach works for QMainWindow derivatives but has some weird behavior for
> > modal dialogs — closeEvent() is called only when the dialog is closed by
> > clicking the "X" button or choosing corresponding window context menu item. If
> > the user presses "OK" or "Cancel" button (or takes some other action that's
> > connected to accept() or reject()), closeEvent() is not called, making the
> > dialog-parameter-saving idea mostly useless.
> > 
> > Is this a bug or intended behavior?
> 
> I guess it's bug, since closeEvent() should be passed before real closing ...and 
> there you can stop it. eg. "Do you really want to close this window (no matter 
> that's modal window or dialog or whatever" ...especially if that triggers on 
> close button ("X").
> 
> zeljko
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110628/7848a911/attachment.bin 


More information about the Qt-interest-old mailing list