Results 1 to 5 of 5

Thread: How Hand the close button in MainWindow

  1. #1
    Join Date
    Oct 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default How Hand the close button in MainWindow

    Hello, I have a problem. I have a MainWindow, and I want hand event when user click close button on MainWindow (x-button). What I should do?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: How Hand the close button in MainWindow

    in your mainwindow, implement closevent(...).


    http://doc.qt.nokia.com/latest/qwidget.html#closeEvent

    If you haven't already, you will need to subclass QMainWindow so that you can implement the method.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Oct 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: How Hand the close button in MainWindow

    I try implement function closeEvent, but my Window still close! Help me!
    Qt Code:
    1. void MainWindow::closeEvent(QCloseEvent *event)
    2. {
    3. event->ignore();
    4. qDebug()<<"Can't close Window";
    5. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: How Hand the close button in MainWindow

    Have you defined the method correctly in your header file?
    Qt Code:
    1. protected:
    2. void closeEvent( QCloseEvent* event );
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: How Hand the close button in MainWindow

    And Importantly, does it inherit from QWidget etc etc.

    Please pay attention to my sig. cut and paste a complete example, otherwise you are making everybody guess!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. QT application not close after close the mainwindow
    By artome in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 23:23
  2. Replies: 2
    Last Post: 6th May 2011, 09:02
  3. Replies: 2
    Last Post: 26th April 2011, 12:44
  4. There Signal Close or Show in MainWindow??
    By macgayver in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2010, 06:35
  5. Replies: 1
    Last Post: 1st June 2006, 13:46

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
  •  
Qt is a trademark of The Qt Company.