QtWidgets: Allow to cover up the window container by another widget

When the window container already has a window handle, allow embedded
windows to use this handle as a parent. This change will allow proper
window stacking and clipping.

Task-number: QTBUG-50477
Change-Id: I8d656ecb99e0c42ae7a7ac461e5e5b5d801f5493
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
Błażej Szczygieł 2016-01-15 02:29:57 +01:00
parent ee9621b9dc
commit 58f8dd4f92
2 changed files with 27 additions and 2 deletions

View File

@ -84,6 +84,11 @@ public:
if (usesNativeWidgets || window->parent() == 0) if (usesNativeWidgets || window->parent() == 0)
return; return;
Q_Q(QWindowContainer); Q_Q(QWindowContainer);
if (q->internalWinId()) {
// Allow use native widgets if the window container is already a native widget
usesNativeWidgets = true;
return;
}
QWidget *p = q->parentWidget(); QWidget *p = q->parentWidget();
while (p) { while (p) {
if ( if (
@ -147,8 +152,10 @@ public:
as a child of a QAbstractScrollArea or QMdiArea, it will as a child of a QAbstractScrollArea or QMdiArea, it will
create a \l {Native Widgets vs Alien Widgets} {native window} for create a \l {Native Widgets vs Alien Widgets} {native window} for
every widget in its parent chain to allow for proper stacking and every widget in its parent chain to allow for proper stacking and
clipping in this use case. Applications with many native child clipping in this use case. Creating a native window for the window
windows may suffer from performance issues. container also allows for proper stacking and clipping. This must
be done before showing the window container. Applications with
many native child windows may suffer from performance issues.
The window container has a number of known limitations: The window container has a number of known limitations:

View File

@ -81,6 +81,7 @@ private slots:
void testActivation(); void testActivation();
void testAncestorChange(); void testAncestorChange();
void testDockWidget(); void testDockWidget();
void testNativeContainerParent();
void cleanup(); void cleanup();
private: private:
@ -330,6 +331,23 @@ void tst_QWindowContainer::testDockWidget()
QTRY_COMPARE(window->parent(), mainWindow.window()->windowHandle()); QTRY_COMPARE(window->parent(), mainWindow.window()->windowHandle());
} }
void tst_QWindowContainer::testNativeContainerParent()
{
QWidget root;
root.setWindowTitle(QTest::currentTestFunction());
root.setGeometry(m_availableGeometry.x() + 50, m_availableGeometry.y() + 50, 200, 200);
Window *window = new Window();
QWidget *container = QWidget::createWindowContainer(window, &root);
container->setAttribute(Qt::WA_NativeWindow);
container->setGeometry(50, 50, 150, 150);
root.show();
QVERIFY(QTest::qWaitForWindowExposed(window));
QTRY_COMPARE(window->parent(), container->windowHandle());
}
QTEST_MAIN(tst_QWindowContainer) QTEST_MAIN(tst_QWindowContainer)
#include "tst_qwindowcontainer.moc" #include "tst_qwindowcontainer.moc"