aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-08-06 13:20:07 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-08-17 09:36:18 +0000
commit761dba8b23b7e558acc57b3e481648ce319a4397 (patch)
treee74e27668dd1c65ec12c0e31d30909b40db261c4
parent7810b97febd0bfe00132dec785c21ca4a361c818 (diff)
Get the scale of the popup item when setting the parent item
As there are some styles that will do an transition which animates the scale then we need to size and position based on the final scale it will have to avoid a jump after it has finished the transition. Fixes: QTBUG-84488 Change-Id: I4571eb18c921e81de319838ac0e8d3fe3513d438 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 64230bf97c18297f45bd5d7ccf99b510c8a612bd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quicktemplates2/qquickpopuppositioner.cpp18
-rw-r--r--src/quicktemplates2/qquickpopuppositioner_p_p.h1
-rw-r--r--tests/auto/controls/data/tst_combobox.qml22
-rw-r--r--tests/auto/controls/data/tst_popup.qml3
4 files changed, 36 insertions, 8 deletions
diff --git a/src/quicktemplates2/qquickpopuppositioner.cpp b/src/quicktemplates2/qquickpopuppositioner.cpp
index dbe8ac1d..1bfaafbe 100644
--- a/src/quicktemplates2/qquickpopuppositioner.cpp
+++ b/src/quicktemplates2/qquickpopuppositioner.cpp
@@ -92,7 +92,10 @@ void QQuickPopupPositioner::setParentItem(QQuickItem *parent)
QQuickItemPrivate::get(parent)->addItemChangeListener(this, ItemChangeTypes);
addAncestorListeners(parent->parentItem());
-
+ // Store the scale property so the end result of any transition that could effect the scale
+ // does not influence the top left of the final popup, so it doesn't appear to flip from one
+ // position to another as a result
+ m_popupScale = m_popup->popupItem()->scale();
if (m_popup->popupItem()->isVisible())
QQuickPopupPrivate::get(m_popup)->reposition();
}
@@ -108,11 +111,10 @@ void QQuickPopupPositioner::reposition()
return;
}
- const qreal scale = popupItem->scale();
- const qreal w = popupItem->width() * scale;
- const qreal h = popupItem->height() * scale;
- const qreal iw = popupItem->implicitWidth() * scale;
- const qreal ih = popupItem->implicitHeight() * scale;
+ const qreal w = popupItem->width() * m_popupScale;
+ const qreal h = popupItem->height() * m_popupScale;
+ const qreal iw = popupItem->implicitWidth() * m_popupScale;
+ const qreal ih = popupItem->implicitHeight() * m_popupScale;
bool widthAdjusted = false;
bool heightAdjusted = false;
@@ -258,9 +260,9 @@ void QQuickPopupPositioner::reposition()
}
if (!p->hasWidth && widthAdjusted && rect.width() > 0)
- popupItem->setWidth(rect.width() / scale);
+ popupItem->setWidth(rect.width() / m_popupScale);
if (!p->hasHeight && heightAdjusted && rect.height() > 0)
- popupItem->setHeight(rect.height() / scale);
+ popupItem->setHeight(rect.height() / m_popupScale);
m_positioning = false;
}
diff --git a/src/quicktemplates2/qquickpopuppositioner_p_p.h b/src/quicktemplates2/qquickpopuppositioner_p_p.h
index 64f57a3f..03a2e2fe 100644
--- a/src/quicktemplates2/qquickpopuppositioner_p_p.h
+++ b/src/quicktemplates2/qquickpopuppositioner_p_p.h
@@ -79,6 +79,7 @@ protected:
bool m_positioning = false;
QQuickItem *m_parentItem = nullptr;
QQuickPopup *m_popup = nullptr;
+ qreal m_popupScale = 1.0;
};
QT_END_NAMESPACE
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index e9156fee..1c58372f 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -911,6 +911,28 @@ TestCase {
compare(control.popup.visible, true)
verify(control.popup.contentItem.y < control.y)
+
+ // Account for when a transition of a scale from 0.9-1.0 that it is placed above right away and not below
+ // first just because there is room at the 0.9 scale
+ if (control.popup.enter !== null) {
+ // hide
+ mouseClick(control)
+ compare(control.pressed, false)
+ tryCompare(control.popup, "visible", false)
+ control.y = control.Window.height - (control.popup.contentItem.height * 0.99)
+ var popupYSpy = createTemporaryObject(signalSpy, testCase, {target: control.popup, signalName: "yChanged"})
+ verify(popupYSpy.valid)
+ mousePress(control)
+ compare(control.pressed, true)
+ compare(control.popup.visible, false)
+ mouseRelease(control)
+ compare(control.pressed, false)
+ compare(control.popup.visible, true)
+ tryCompare(control.popup.enter, "running", false)
+ verify(control.popup.contentItem.y < control.y)
+ verify(popupYSpy.count === 1)
+ }
+
// follow the control outside the horizontal window bounds
control.x = -control.width / 2
compare(control.x, -control.width / 2)
diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml
index 71d6f2d7..57d5cccc 100644
--- a/tests/auto/controls/data/tst_popup.qml
+++ b/tests/auto/controls/data/tst_popup.qml
@@ -1276,6 +1276,9 @@ TestCase {
{ visible: true, width: 100, height: 100 })
verify(control)
verify(control.visible)
+ // If there is a transition then make sure it is finished
+ if (control.enter !== null)
+ tryCompare(control.enter, "running", false)
compare(control.parent, control.Overlay.overlay)
compare(control.x, 0)
compare(control.y, 0)