From 659c889f64e76ec9aece2dd9e24a7f65875c46ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Mon, 15 Nov 2010 08:56:58 +0100 Subject: Add autotest to test a issue with stretches and preferred width. The issue seemed to claim that the preferred size was not respected when there was another item that could stretch along the same axis: "A widget with a horizontal stretch next to it should get its preferredWidth()". This seems to works as expected, so nothing to fix. Task-number: QTBUG-12835 --- .../tst_qgraphicsgridlayout.cpp | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index e448e4c..7170059 100644 --- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -122,6 +122,7 @@ private slots: void task236367_maxSizeHint(); void heightForWidth(); void heightForWidthWithSpanning(); + void stretchAndHeightForWidth(); }; class RectWidget : public QGraphicsWidget @@ -2806,6 +2807,67 @@ void tst_QGraphicsGridLayout::heightForWidthWithSpanning() QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 10000)); } + +void tst_QGraphicsGridLayout::stretchAndHeightForWidth() +{ + QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); + QGraphicsGridLayout *layout = new QGraphicsGridLayout; + widget->setLayout(layout); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + + RectWidget *w1 = new RectWidget; + w1->setSizeHint(Qt::MinimumSize, QSizeF(10, 10)); + w1->setSizeHint(Qt::PreferredSize, QSizeF(100, 100)); + w1->setSizeHint(Qt::MaximumSize, QSizeF(500, 500)); + layout->addItem(w1, 0,0,1,1); + + RectWidget *w2 = new RectWidget; + w2->setSizeHint(Qt::MinimumSize, QSizeF(10, 10)); + w2->setSizeHint(Qt::PreferredSize, QSizeF(100, 100)); + w2->setSizeHint(Qt::MaximumSize, QSizeF(500, 500)); + layout->addItem(w2, 0,1,1,1); + layout->setColumnStretchFactor(1, 2); + + QApplication::sendPostedEvents(); + QGraphicsScene scene; + QGraphicsView *view = new QGraphicsView(&scene); + + scene.addItem(widget); + + view->show(); + + widget->resize(500, 100); + // w1 should stay at its preferred size + QCOMPARE(w1->geometry(), QRectF(0, 0, 100, 100)); + QCOMPARE(w2->geometry(), QRectF(100, 0, 400, 100)); + + + // only w1 has hfw + w1->setConstraintFunction(hfw); + QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred); + sp.setHeightForWidth(true); + w1->setSizePolicy(sp); + QApplication::sendPostedEvents(); + + QCOMPARE(w1->geometry(), QRectF(0, 0, 100, 200)); + QCOMPARE(w2->geometry(), QRectF(100, 0, 400, 200)); + + // only w2 has hfw + w2->setConstraintFunction(hfw); + w2->setSizePolicy(sp); + + w1->setConstraintFunction(0); + sp.setHeightForWidth(false); + w1->setSizePolicy(sp); + QApplication::sendPostedEvents(); + + QCOMPARE(w1->geometry(), QRectF(0, 0, 100, 100)); + QCOMPARE(w2->geometry(), QRectF(100, 0, 400, 50)); + +} + + QTEST_MAIN(tst_QGraphicsGridLayout) #include "tst_qgraphicsgridlayout.moc" -- cgit v0.12