summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2010-11-15 07:56:58 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2010-11-15 07:56:58 (GMT)
commit659c889f64e76ec9aece2dd9e24a7f65875c46ad (patch)
tree2789f2e38b7acb918764dabd478f13ceee9c4bf9 /tests
parent8f23788ec21896135f182778cf48362162b88969 (diff)
downloadQt-659c889f64e76ec9aece2dd9e24a7f65875c46ad.zip
Qt-659c889f64e76ec9aece2dd9e24a7f65875c46ad.tar.gz
Qt-659c889f64e76ec9aece2dd9e24a7f65875c46ad.tar.bz2
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
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp62
1 files changed, 62 insertions, 0 deletions
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"