Results 1 to 6 of 6

Thread: CloseEvent of QDockWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default CloseEvent of QDockWidget

    Hello,

    With the designer I created a MainWindow with a few DockWidgets. The widget of the DockWidget I promoted to my custom widget. Works nice.

    But the closeEvent of the DockWidget is not forwarded to the widget of the DockWidget. Therefor I can not handle a graceful close of my custom widget. (CustomWidget::closeEvent (QCloseEvent) not called);

    How can I handle the close of the DockWidget so I can graceful close the custom widget?

    Regards,

    Marcel

  2. #2
    Join Date
    Mar 2007
    Posts
    57
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: CloseEvent of QDockWidget

    Did you re-implement closeEvent in your subclass? Maybe you can provide the header file?

  3. #3
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: CloseEvent of QDockWidget

    Yes I did reimplement the CustomWidget::closeEvent (QCloseEvent) and that one is not called. If I look at the QDockWidget::closeEvent I see that it only calls its inherited class and not its childeren. So I think that the QDockWidget:: closeEvent does not propagate the close event to the widgets that are set with setWidget.

    I could use the VisibilityChanged signal I guess.

    Regards,

    Marcel

  4. #4
    Join Date
    Mar 2007
    Posts
    57
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: CloseEvent of QDockWidget

    My example below works and I think that's what you want. Compare with your code to see what's wrong

    Main.cpp:
    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3. #include <Test.h>
    4.  
    5. int main (int argc, char **argv)
    6. {
    7. QApplication app (argc, argv);
    8.  
    9. Test *lDW = new Test("Test", w);
    10. w->show();
    11.  
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Test.h:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Test : public QDockWidget
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. Test (const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0) : QDockWidget (title, parent, flags)
    9. {
    10. }
    11.  
    12. protected:
    13. void closeEvent (QCloseEvent *event)
    14. {
    15. printf ("closeEvent!\n");
    16. }
    17. };
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: CloseEvent of QDockWidget

    I definitly want that but it is slightly more complex as I use the designer. The designer generates this code:

    Qt Code:
    1. m_dockWidget = new QDockWidget(MainWindowBase);
    2. ...
    3. m_customWidget = new CustomWidget();
    4. ...
    5. m_dockWidget ->setWidget(m_dockWidget );
    6. MainWindowBase->addDockWidget(static_cast<Qt::DockWidgetArea>(4), m_dockWidget );
    To copy to clipboard, switch view to plain text mode 

    In my custom widget I would like to know the close event of its parent (dockwidget).

    In the designer the custom widget is set using the 'promote to' option.

    Regards,

    Marcel

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: CloseEvent of QDockWidget

    From the parent, pass on the close event info to the child... hope u can do that

Similar Threads

  1. QDialog and closeEvent
    By ricardo in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2009, 02:07
  2. exit(0) does not call closeEvent
    By ricardo in forum Qt Programming
    Replies: 4
    Last Post: 25th June 2009, 07:39
  3. QSettings and closeEvent()
    By vito49 in forum Newbie
    Replies: 2
    Last Post: 13th October 2008, 16:18
  4. closeEvent help needed
    By sgmurphy19 in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 17:51
  5. closeEvent
    By jochen_r in forum Newbie
    Replies: 7
    Last Post: 16th January 2006, 12:05

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.