ensure signal subWindowActivated() triggers even when widget has focus

A widget being added to QMdiArea which currently has focus
did not trigger the subWindowActivated() signal
since the connection to the method _q_processWindowStateChanged, which
emits the signal (set up in appendChild()), was just done after
the focus was set back again to the added widget.
Setting the focus makes the widget active.
This patch changes the order: first call appendChild(), then set focus

Change-Id: I3aaf1728dc082d1323c7fbd62bfdbd2af87ab2ce
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Martin Koller 2019-01-04 21:58:51 +01:00
parent 035f934d7a
commit 6a31466951
2 changed files with 4 additions and 1 deletions

View File

@ -1988,9 +1988,11 @@ QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFla
Q_ASSERT(child->testAttribute(Qt::WA_DeleteOnClose));
}
d->appendChild(child);
if (childFocus)
childFocus->setFocus();
d->appendChild(child);
return child;
}

View File

@ -333,6 +333,7 @@ void tst_QMdiArea::subWindowActivated()
for ( i = 0; i < count; ++i ) {
QWidget *widget = new QWidget(workspace, 0);
widget->setAttribute(Qt::WA_DeleteOnClose);
widget->setFocus();
workspace->addSubWindow(widget)->show();
widget->show();
qApp->processEvents();