I have QMdiArea
object in QMainWindow
which I did not have set with setCentralWidget()
but as mentioned below.
MainWindow::createMdiArea() {
QMdiArea mdiArea = new QMdiArea(this)
mdiArea.setGeometry(0,0,1024,600);
mdiArea.show();
}
I don't want to set this QMdiArea
as the center widget. Now I am creating some child windows inside this QMdiArea
, as following
MainWindow::createChildWindow()
{
HelpWindow child1 = new HelpWindow(). // HelpWindow is a very simple class derived from QWidget and containing one QLineEdit.
mdiArea.addSubWindow(&child1);
// Set the geometry of Child widget.
child1.parentWidget()->setGeometry(0,0,400,100); // Setting geometry which I have saved.
child1.show();
}
So far so good. But the problem is in the child window resize / close events I need to save the size of the HelpWindow
and I am doing following to save the size of the child window in its resize / close events.
saveHelpWindowSize(size());
saveHelpWindowPos(pos());
Ok. Here comes the problem. The size I have got from the size()
function inside the child window is different from the one which I have used in setGeometry()
function, even I see it in some method other than resize event (i.e Close event).
So, Suppose first time the child window was created with the size (using setGeometry) 400, 200, when I go to close this window the size I will get from HelpWindow::size()
might be say (385, 190)
which I will save, and next time setGeometry()
will get this size from settings, and at this time on close event I will get more smaller size, and eventually my child window will have size (0, 0)
.
1: Any thoughts on how to sync both these sizes (i.e., the size if the child widget being set by setGeometry()
function and the size of the widget I am getting from size()
function of the widget)
2: Another question, I am receiving resizeEvent / closeEvent events etc in the child widget (HelpWindow
) class, but I am not getting moveEvent when I move the child window inside QMdiArea
, the only time I receive this event is when I maximize the child window inside QMdiArea
(which I won't be doing). So I need to save the position of my child window when its position is changed. How can I do it?