summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel/qwidget
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-02-17 15:08:58 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-02-19 20:04:19 +0000
commit8c3cc07bf5254cb91b37a0000191871e9e32014e (patch)
tree04e79baebbb37dfd4fde9b9a1e2a6691861e4ef0 /tests/auto/widgets/kernel/qwidget
parentfc3226e7909812092e9e1acdd45140427b3a4cf0 (diff)
widgets: Translate QWindow move events into widget relative position
If a widget backed by a QWindow is moved we need to translate the window geometry into a position relative to the parent widget. In most cases this was incidentally working due to widgets backed by QWindows always having QWindow parents too, so the QWindow position was applicable to the widget as well. But when Qt::WA_DontCreateNativeAncestors is used this is no longer the case, and we would end up with a widget geometry that included the parent positions all the way up to the next native widget. The updatePos() function has been squashed into handleMoveEvent(), since we need to ensure the position in the move event sent to the widget is correct as well. Change-Id: I55894ad7ab42a6d4d65e446a332ecdd7dcdcc263 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/widgets/kernel/qwidget')
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index d8f4881ffa..31e77b2a62 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -310,6 +310,8 @@ private slots:
void hideOpaqueChildWhileHidden();
void updateWhileMinimized();
void alienWidgets();
+ void nativeWindowPosition_data();
+ void nativeWindowPosition();
void adjustSize();
void adjustSize_data();
void updateGeometry();
@@ -8211,6 +8213,40 @@ void tst_QWidget::alienWidgets()
}
}
+using WidgetAttributes = QVector<Qt::WidgetAttribute>;
+
+void tst_QWidget::nativeWindowPosition_data()
+{
+ QTest::addColumn<WidgetAttributes>("attributes");
+
+ QTest::newRow("non-native all the way")
+ << WidgetAttributes{};
+ QTest::newRow("native all the way")
+ << WidgetAttributes{ Qt::WA_NativeWindow };
+ QTest::newRow("native with non-native ancestor")
+ << WidgetAttributes{ Qt::WA_NativeWindow, Qt::WA_DontCreateNativeAncestors };
+}
+
+void tst_QWidget::nativeWindowPosition()
+{
+ QWidget topLevel;
+ QWidget child(&topLevel);
+ child.move(5, 5);
+
+ QWidget grandChild(&child);
+ grandChild.move(10, 10);
+
+ QFETCH(WidgetAttributes, attributes);
+ for (auto attribute : attributes)
+ grandChild.setAttribute(attribute);
+
+ topLevel.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+
+ QCOMPARE(child.pos(), QPoint(5, 5));
+ QCOMPARE(grandChild.pos(), QPoint(10, 10));
+}
+
class ASWidget : public QWidget
{
public: