aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickpopup.cpp5
-rw-r--r--tests/auto/controls/data/tst_popup.qml24
2 files changed, 28 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index 8c0e5990..2a48473a 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -595,7 +595,10 @@ void QQuickPopupPrivate::reposition()
if (window) {
const QMarginsF margins = getMargins();
- const QRectF bounds = QRectF(0, 0, window->width(), window->height()).marginsRemoved(margins);
+ const QRectF bounds(qMax<qreal>(0.0, margins.left()),
+ qMax<qreal>(0.0, margins.top()),
+ window->width() - qMax<qreal>(0.0, margins.left()) - qMax<qreal>(0.0, margins.right()),
+ window->height() - qMax<qreal>(0.0, margins.top()) - qMax<qreal>(0.0, margins.bottom()));
// if the popup doesn't fit horizontally inside the window, try flipping it around (left <-> right)
if (allowHorizontalFlip && (rect.left() < bounds.left() || rect.right() > bounds.right())) {
diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml
index 919bfffc..ae1c7185 100644
--- a/tests/auto/controls/data/tst_popup.qml
+++ b/tests/auto/controls/data/tst_popup.qml
@@ -355,6 +355,30 @@ TestCase {
control.destroy()
}
+ function test_negativeMargins() {
+ var control = popupControl.createObject(testCase, {implicitWidth: testCase.width, implicitHeight: testCase.height})
+ verify(control)
+
+ control.open()
+ verify(control.visible)
+
+ compare(control.x, 0)
+ compare(control.y, 0)
+
+ compare(control.margins, -1)
+ compare(control.topMargin, -1)
+ compare(control.leftMargin, -1)
+ compare(control.rightMargin, -1)
+ compare(control.bottomMargin, -1)
+
+ control.x = -10
+ control.y = -10
+ compare(control.x, 0)
+ compare(control.y, 0)
+
+ control.destroy()
+ }
+
function test_margins() {
var control = popupControl.createObject(testCase, {width: 100, height: 100})
verify(control)