PDA

View Full Version : Close a QMdiSubwindow



John_P
11th March 2008, 10:21
Hi,

Is there a way to close a QMdiSubwindow using the central widget?

In the MDI example, child->close() is called but this leaves the QMdiSubwindow in the QMdiArea subWindowList. I would like to call close() on the QMdiSubwindow so it is removed from the subWindowList but I can't find a way to obtain the QMdiSubwindow from the central widget.

Thanks.

John

wysota
11th March 2008, 10:51
Delete the widget afterwards. close() only hides it, not destroyes it, thus it's still in the list.

John_P
11th March 2008, 11:25
Thanks Wysota for your quick reply. My child widget has the attribute WA_DeleteOnClose so I presume child->close() will have deleted it.

Anyway, I found a way to get the QMdiSubWindow from the child as

QMdiSubWindow* QMdiChild = qobject_cast<QMdiSubWindow*>(child->parentWidget());

Calling QMdiChild->close() deletes the central widget AND the mdi subwindow so I am happy.

Thanks again,

John.

fnmblot
14th March 2008, 16:31
I have been having the same problem. I thought doing the setAttribute(Qt::WA_DeleteOnClose) would delete the sub window when you call a close(), but it is not for me. Am I doing this wrong?


void nnDBSMainWindow::pieceEntry()
{
nnDBSPieceEntry *pieceEntry = new nnDBSPieceEntry;
QMdiSubWindow *swPieceEntry = new QMdiSubWindow;
swPieceEntry->setWidget(pieceEntry);
MDIArea->addSubWindow(swPieceEntry);
swPieceEntry->setAttribute(Qt::WA_DeleteOnClose);
swPieceEntry->setWindowFlags(Qt::WindowTitleHint);
swPieceEntry->show();
swPieceEntry->resize(650, 600);
}//End pieceEntry

jpn
14th March 2008, 18:23
As John_P mentioned, it's not enough to call pieceEntry->close() but you have to call swPieceEntry->close().