Results 1 to 4 of 4

Thread: Message on close(x) button of Form

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Message on close(x) button of Form

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Message on close(x) button of Form

    Quote Originally Posted by vishal.chauhan View Post
    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..
    J-P Nurmi

  3. #3
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Message on close(x) button of Form

    Thanks.
    It is working Now.
    Last edited by vishal.chauhan; 29th January 2007 at 09:39.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Message on close(x) button of Form

    Qt Code:
    1. if (QMessageBox::question(...) == QMessageBox::Yes)
    2. {
    3. // ignore event, the window is not closed
    4. event->ignore();
    5. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following 2 users say thank you to jpn for this useful post:

    vishal.chauhan (29th January 2007), WinchellChung (19th March 2008)

Similar Threads

  1. How to create an Insert/Submit button for a form.
    By fnmblot in forum Qt Programming
    Replies: 5
    Last Post: 4th August 2006, 16:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.