MdiArea
-
Hi all
I have a problem managing the subwindows in the MdiArea component
The problem is very simple, when Adding a widget as a subwindow to the MdiArea this doesn't preserve the geometry defined in the designer.
Sample code:@ MyWidget * w=new MyWidget(this);
ui->mdiArea->addSubWindow(w);
w->show();@So I've tried to play with the geometry like this sample code:
@
setGeometry(geometry().x(),geometry().y(),348,500);
updateGeometry();
@But I got no success :(
What I've tried next is to set the geometry in the same block of code where adding the subwindow, in different places but also got no success.Is it a bug in the MdiArea??
Thanks in advance -
I would do it like this:
@QMdiSubWindow *w = ui->mdiArea->addSubWindow(new MyWidget());
w->show();@Subtle difference there. I'm not sure which class you mean by "this" and what geometry should be preserved? If you want to use fixed geometry, set a fixed size in the designer. Best practice is to almost always use resizable windows (use layouts).
It is probably not a bug in the MDI area.
-
MDI windows are almost always meant to be resized. So like Franzk says: best is to make sure you handle that case.
Anyway, what happens if you modify your code like this:
@
MyWidget * w=new MyWidget(this);
QMdiSubWindow* subwindow = ui->mdiArea->addSubWindow(w);
w->show();
subwindow->setGeometry(subwindow->geometry().x(),subwindow->geometry().y(),348,500);
@Note that you will probably need to adjust the size a bit, because the style adds borders. This size will be different per style, so you will have to figure out the adjustment in some dynamic way.