Closing QMdiSubWindow From Within Widget
-
Anybody know the proper way to close a QMdiSubWindow programmatically from within the QWidget it contains? For instance, I have a requirement to put a "Close" button on a form, which when clicked should close the QMdiSubWindow that contains the form. The best solution I've come up with is to set the parent of the form to the QMdiSubWindow and then connect the button's clicked() signal to the close slot of the parentWidget. Such as:
@
QMdiSubWindow* sw = new QMdiSubWindow( mdiArea );
sw->setWidget( new MyForm( sw ) );
sw->setAttribute( Qt::WA_DeleteOnClose );
mdiArea->addSubWindow( sw );
sw->show();
@Then within MyForm constructor I would connect the signal:
@
connect( closeButton, SIGNAL( clicked() ),
parentWidget(), SLOT( close() ) );
@This approach only works if MyForm's parentWidget is the QMdiSubWindow. I can't help thinking there must be a better way. Seems like there should be some kind of property or attribute on QMdiSubWindow like "close me when widget closes" but I haven't found it. Anyone have any ideas?
-
It's in the docs of "QMdiArea::addSubWindow() ":http://doc.qt.nokia.com/4.7/qmdiarea.html#addSubWindow