summaryrefslogtreecommitdiffstats
path: root/tests/auto/qlayout
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-20 11:04:56 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-20 14:25:24 (GMT)
commitaf17ea048179ea0c21a897f803e79f825a9d13b6 (patch)
treec886de07268e9fa33c65cdb67256e87da1f35058 /tests/auto/qlayout
parent856efef9bf87e0b7e5ed6ad2ccb225e294321888 (diff)
downloadQt-af17ea048179ea0c21a897f803e79f825a9d13b6.zip
Qt-af17ea048179ea0c21a897f803e79f825a9d13b6.tar.gz
Qt-af17ea048179ea0c21a897f803e79f825a9d13b6.tar.bz2
Make adjustSize work even if there is a pending LayoutRequest event.
The original report was that the customer did resize(main.sizeHint()) instead of the main.adjustSize(); Note that resize(main.sizeHint() still does not work. However, calling main.adjustSize() should now do what the original reporter wanted. The problem was that the resize did not work, because at the point of the resize the minimumHeight of main was still 22 (8+6+8), and we tried to resize it with a new height of 10. The resize would bound the height up to 22, and the main widget would then get a size of (200x22). The reason why it still had a minimumHeight of 22 was that it was the minimumSize of the previous layout configuration. Unfortunately the new minimumSize of the widget hadn't been updated yet because there was a LayoutRequest event in the queue that hadn't been processed yet. (This LayoutRequest was triggered by that we called invalidate() from hide()). Thus, processing the event queue immediately after the hide() could also have been a workaround for this issue. There is no really good fix for this issue (and it does not seem to be a common problem) without introducing a risk for regressions. Due to that we therefore decided to provide a fix in QWidget::adjustSize(). Reviewed-by: paul
Diffstat (limited to 'tests/auto/qlayout')
-rw-r--r--tests/auto/qlayout/tst_qlayout.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/auto/qlayout/tst_qlayout.cpp b/tests/auto/qlayout/tst_qlayout.cpp
index 9d6110d..efe14c3 100644
--- a/tests/auto/qlayout/tst_qlayout.cpp
+++ b/tests/auto/qlayout/tst_qlayout.cpp
@@ -83,6 +83,7 @@ private slots:
void layoutItemRect();
void warnIfWrongParent();
void controlTypes();
+ void adjustSizeShouldMakeSureLayoutIsActivated();
};
tst_QLayout::tst_QLayout()
@@ -110,8 +111,8 @@ void tst_QLayout::getSetCheck()
class SizeHinterFrame : public QFrame
{
public:
- SizeHinterFrame(const QSize &s)
- : QFrame(0), sh(s) {
+ SizeHinterFrame(const QSize &sh, const QSize &msh = QSize())
+ : QFrame(0), sh(sh), msh(msh) {
setFrameStyle(QFrame::Box | QFrame::Plain);
}
@@ -119,9 +120,11 @@ public:
void setSizeHint(const QSize &s) { sh = s; }
QSize sizeHint() const { return sh; }
+ QSize minimumSizeHint() const { return msh; }
private:
QSize sh;
+ QSize msh;
};
@@ -333,5 +336,26 @@ void tst_QLayout::controlTypes()
}
+void tst_QLayout::adjustSizeShouldMakeSureLayoutIsActivated()
+{
+ QWidget main;
+
+ QVBoxLayout *const layout = new QVBoxLayout(&main);
+ layout->setMargin(0);
+ SizeHinterFrame *frame = new SizeHinterFrame(QSize(200, 10), QSize(200, 8));
+ frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ layout->addWidget(frame);
+
+ SizeHinterFrame *frame2 = new SizeHinterFrame(QSize(200, 10), QSize(200, 8));
+ frame2->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ layout->addWidget(frame2);
+
+ main.show();
+
+ frame2->hide();
+ main.adjustSize();
+ QCOMPARE(main.size(), QSize(200, 10));
+}
+
QTEST_MAIN(tst_QLayout)
#include "tst_qlayout.moc"