From 0b2d05093c6fc030d40be8c873ad1e0af9bba8cc Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 21 Feb 2014 15:04:21 +0100 Subject: QQuickWindow: fix content item size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resize content item in QQuickWindow::resizeEvent() instead of using signals and slots. The signal-slot connections were only established when child items were added in QML. It should work in C++ too, since QQuickWindow and QQuickItem are part of the public C++ API and using them in C++ is a perfectly valid use case. Resizing the content item in resizeEvent() is not only faster than using signals and slots, but also in theory a bit more flexible as one would be able to override the event handler and implement their own layouting. Task-number: QTBUG-36938 Change-Id: Id05d4cf6d547021803050633e6f0a3359129a9f3 Reviewed-by: Alan Alpert Reviewed-by: Mitch Curtis Reviewed-by: Gunnar Sletta Reviewed-by: Jan Arve Sæther --- tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/auto/quick/qquickwindow/tst_qquickwindow.cpp') diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 73e45fa719..3735947356 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -355,6 +355,8 @@ private slots: void animatingSignal(); + void contentItemSize(); + private: QTouchDevice *touchDevice; QTouchDevice *touchDeviceWithVelocity; @@ -1707,6 +1709,38 @@ void tst_qquickwindow::animatingSignal() QTRY_VERIFY(spy.count() > 1); } +// QTBUG-36938 +void tst_qquickwindow::contentItemSize() +{ + QQuickWindow window; + QQuickItem *contentItem = window.contentItem(); + QVERIFY(contentItem); + QCOMPARE(QSize(contentItem->width(), contentItem->height()), window.size()); + + QSizeF size(300, 200); + window.resize(size.toSize()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QCOMPARE(window.size(), size.toSize()); + QCOMPARE(QSizeF(contentItem->width(), contentItem->height()), size); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData(QByteArray("import QtQuick 2.1\n Rectangle { anchors.fill: parent }"), QUrl()); + QQuickItem *rect = qobject_cast(component.create()); + QVERIFY(rect); + rect->setParentItem(window.contentItem()); + QCOMPARE(QSizeF(rect->width(), rect->height()), size); + + size.transpose(); + window.resize(size.toSize()); + QCOMPARE(window.size(), size.toSize()); + // wait for resize event + QTRY_COMPARE(QSizeF(contentItem->width(), contentItem->height()), size); + QCOMPARE(QSizeF(rect->width(), rect->height()), size); +} + QTEST_MAIN(tst_qquickwindow) #include "tst_qquickwindow.moc" -- cgit v1.2.3