PDA

View Full Version : CloseEvent of QDockWidget



mstegehu
11th March 2010, 10:52
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

TMan
11th March 2010, 11:47
Did you re-implement closeEvent in your subclass? Maybe you can provide the header file?

mstegehu
11th March 2010, 13:45
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

TMan
11th March 2010, 16:58
My example below works and I think that's what you want. Compare with your code to see what's wrong :)

Main.cpp:

#include <QtCore>
#include <QtGui>
#include <Test.h>

int main (int argc, char **argv)
{
QApplication app (argc, argv);

QMainWindow *w = new QMainWindow();
Test *lDW = new Test("Test", w);
w->show();

return app.exec();
}

Test.h:

#include <QtGui>

class Test : public QDockWidget
{
Q_OBJECT

public:
Test (const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0) : QDockWidget (title, parent, flags)
{
}

protected:
void closeEvent (QCloseEvent *event)
{
printf ("closeEvent!\n");
}
};

mstegehu
16th March 2010, 09:45
I definitly want that but it is slightly more complex as I use the designer. The designer generates this code:



m_dockWidget = new QDockWidget(MainWindowBase);
...
m_customWidget = new CustomWidget();
...
m_dockWidget ->setWidget(m_dockWidget );
MainWindowBase->addDockWidget(static_cast<Qt::DockWidgetArea>(4), m_dockWidget );


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

aamer4yu
16th March 2010, 14:10
From the parent, pass on the close event info to the child... hope u can do that :rolleyes: