From bd4a19963e102f4a89fdc1f17349909605324519 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 10 Sep 2014 08:31:35 +0200 Subject: [PATCH] Respect contents margins when calculating the size hint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this part of the calendar widget get cut off when put in a layout and the contentsMargins are non zero. Task-number: QTBUG-40352 Change-Id: I9ce90476c59c270d92e876a5dc81ea8ce325848c Reviewed-by: Lars Knoll Reviewed-by: Shawn Rutledge Reviewed-by: Jan Arve Sæther --- src/widgets/widgets/qcalendarwidget.cpp | 3 +++ .../widgets/qcalendarwidget/tst_qcalendarwidget.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index d6704c20d2..fa3dbc1f32 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -2247,6 +2247,9 @@ QSize QCalendarWidget::minimumSizeHint() const w *= cols; w = qMax(headerSize.width(), w); h = (h * rows) + headerSize.height(); + QMargins cm = contentsMargins(); + w += cm.left() + cm.right(); + h += cm.top() + cm.bottom(); d->cachedSizeHint = QSize(w, h); return d->cachedSizeHint; } diff --git a/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp b/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp index e3e7b13cbe..d0a787d32a 100644 --- a/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp +++ b/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp @@ -67,6 +67,8 @@ private slots: void showPrevNext(); void firstDayOfWeek(); + + void contentsMargins(); }; // Testing get/set functions @@ -391,5 +393,13 @@ void tst_QCalendarWidget::firstDayOfWeek() QCOMPARE(calendar.firstDayOfWeek(), germanLocale.firstDayOfWeek()); } +void tst_QCalendarWidget::contentsMargins() +{ + QCalendarWidget calendar1; + QCalendarWidget calendar2; + calendar2.setContentsMargins(10, 5, 20, 30); + QCOMPARE(calendar1.minimumSizeHint() + QSize(30, 35), calendar2.minimumSizeHint()); +} + QTEST_MAIN(tst_QCalendarWidget) #include "tst_qcalendarwidget.moc"