diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2014-02-21 15:04:21 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-28 14:32:47 +0100 |
commit | 0b2d05093c6fc030d40be8c873ad1e0af9bba8cc (patch) | |
tree | fb3830dd4c8377da665ef6423b84baef85a2fe64 /tests/auto/quick/qquickwindow | |
parent | 10f0485464acebd281f37b78f9ab5d02ee4ada9b (diff) |
QQuickWindow: fix content item size
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 <aalpert@blackberry.com>
Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickwindow')
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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<QQuickItem *>(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" |