void tst_QFormLayout::setFieldGrowthPolicy() { QWidget window; QLineEdit fld1, fld2, fld3; fld1.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); fld2.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); fld3.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QFormLayout layout; layout.addRow("One:", &fld1); layout.addRow("Two:", &fld2); layout.addRow("Three:", &fld3); window.setLayout(&layout); window.resize(1000, 200); for (int i = 0; i < 3; ++i) { layout.setFieldGrowthPolicy(i == 0 ? QFormLayout::FieldsStayAtSizeHint : i == 1 ? QFormLayout::ExpandingFieldsGrow : QFormLayout::AllNonFixedFieldsGrow); layout.activate(); if (i == 0) { QVERIFY(fld1.width() == fld2.width()); QVERIFY(fld2.width() == fld3.width()); } else if (i == 1) { QVERIFY(fld1.width() == fld2.width()); QVERIFY(fld2.width() < fld3.width()); } else { QVERIFY(fld1.width() < fld2.width()); QVERIFY(fld2.width() == fld3.width()); } } }
void tst_QFormLayout::layoutAlone() { QWidget w; QFormLayout layout; layout.setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); w.setLayout(&layout); QLabel label("Here is a strange test case"); layout.setWidget(0, QFormLayout::LabelRole, &label); QHBoxLayout hlay; layout.setLayout(1, QFormLayout::LabelRole, &hlay); QCOMPARE(layout.count(), 2); w.show(); layout.activate(); QTest::qWait(500); }