From 05b75bcea1a2d377584f360f28a66084b2cf8970 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether <jan-arve.saether@digia.com> Date: Tue, 14 May 2013 12:34:06 +0200 Subject: [PATCH] Quick Layouts: Do not arrange items at sub-pixel positions. Positioning an item to a sub-pixel position might cause the item to not appear as crisp as it should be. To prevent this, the layout will round off the position and size to the nearest integer. Task-number: QTBUG-31038 Change-Id: Id07b9ed5adc64e07f08f1abe0f37716101b01456 Reviewed-by: Caroline Chao <caroline.chao@digia.com> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> --- src/layouts/qquickgridlayoutengine_p.h | 5 ++-- tests/auto/controls/data/tst_rowlayout.qml | 31 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/layouts/qquickgridlayoutengine_p.h b/src/layouts/qquickgridlayoutengine_p.h index 67b0257bc..29317ffbb 100644 --- a/src/layouts/qquickgridlayoutengine_p.h +++ b/src/layouts/qquickgridlayoutengine_p.h @@ -111,8 +111,9 @@ public: void setGeometry(const QRectF &rect) { - m_item->setPosition(rect.topLeft()); - m_item->setSize(rect.size()); + const QRect r(rect.toRect()); + m_item->setPosition(r.topLeft()); + m_item->setSize(r.size()); } QQuickItem *layoutItem() const { return m_item; } diff --git a/tests/auto/controls/data/tst_rowlayout.qml b/tests/auto/controls/data/tst_rowlayout.qml index 1b9573e0c..505b35171 100644 --- a/tests/auto/controls/data/tst_rowlayout.qml +++ b/tests/auto/controls/data/tst_rowlayout.qml @@ -543,5 +543,36 @@ Item { layout.destroy(); } + + + Component { + id: layout_alignToPixelGrid_Component + RowLayout { + spacing: 2 + Rectangle { + implicitWidth: 10 + implicitHeight: 10 + Layout.alignment: Qt.AlignVCenter + } + Rectangle { + implicitWidth: 10 + implicitHeight: 10 + Layout.alignment: Qt.AlignVCenter + } + } + } + function test_alignToPixelGrid() + { + var layout = layout_alignToPixelGrid_Component.createObject(container) + layout.width = 21 + layout.height = 21 + var r0 = layout.children[0] + compare(r0.x, 0) // 0.0 + compare(r0.y, 6) // 5.5 + var r1 = layout.children[1] + compare(r1.x, 12) // 11.5 + compare(r1.y, 6) // 5.5 + layout.destroy(); + } } } -- GitLab