Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.11.1
-
None
Description
When calling addSubwindow on QMdiArea, whether you pass a widget or create the MdiSubWindow yourself, the subwindow ignores its own size hint. In my particular case I design a QWidget form in the UI designer that I pass to addSubwindow. This means that when the subwindow opens it doesn't have the size of the QWidget as I designed it in the designer.
The workaround I have discovered is to resize the subwindow myself after creating it, but this isn't always easy and honestly Qt should be doing this for me. Unlike QWindow, resize sets the size of the entire QMdiSubwindow and not just the client rect, so you need to account for the frame size.
https://stackoverflow.com/questions/19591641/initial-size-for-qmdisubwindow/29271999
Form* form = new Form(this); QMdiSubWindow* subWindow = new QMdiSubWindow(this); subWindow->setWidget(form); // compute size of subwindow's frame auto borderSize = (subWindow->sizeHint() - form->sizeHint()); auto clientSize = QSize(400,400); // resize the subwindow to the frame size plus desired client area subWindow->resize(borderSize + clientSize); // finally display the subwindow ui->mdiArea->addSubWindow(subWindow);
The best work around seems to be overriding the size hints of the main widget for the subwindow.
virtual QSize sizeHint() const override { return QSize(400,400); }