PDA

View Full Version : Message on close(x) button of Form



vishal.chauhan
29th January 2007, 07:47
Hi All,

I m using Qt 4.2.2 on my Intel Mac.
I have a MainWindow form in which I have the Default close(X) button on the upper Left Corner of the form.
I want that when I click that button it not close the form rather it would ask for what to do whether to exit or not by giving a message.

Also It should give message if I close it through (command+Q) or close it through the Menu Bar.

If any one knows then plz Help me.

Thanks.

jpn
29th January 2007, 08:17
I have a MainWindow form in which I have the Default close(X) button on the upper Left Corner of the form.
I want that when I click that button it not close the form rather it would ask for what to do whether to exit or not by giving a message.

Reimplement QWidget::closeEvent(). Popup a QMessageBox and ignore the event in case user doesn't confirm the quit.



Also It should give message if I close it through (command+Q) or close it through the Menu Bar.
Implement a custom slot and connect the action's triggered() signal to that custom slot instead of close() or to whatever it's currently connected..

vishal.chauhan
29th January 2007, 09:22
Thanks.
It is working Now.

jpn
29th January 2007, 09:39
if (QMessageBox::question(...) == QMessageBox::Yes)
{
// ignore event, the window is not closed
event->ignore();
}