diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 00c23856280..e11f20101e9 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -384,8 +384,19 @@ QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const for (int i = 0; i < count && !hasIcon; ++i) hasIcon = !q->itemIcon(i).isNull(); } - if (minimumContentsLength > 0) - sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.horizontalAdvance(u'X') + (hasIcon ? iconSize.width() + 4 : 0))); + if (minimumContentsLength > 0) { + auto r = qint64{minimumContentsLength} * fm.horizontalAdvance(u'X'); + if (hasIcon) + r += iconSize.width() + 4; + if (r <= QWIDGETSIZE_MAX) { + sh.setWidth(qMax(sh.width(), int(r))); + } else { + qWarning("QComboBox: cannot take minimumContentsLength %d into account for sizeHint(), " + "since it causes the widget to be wider than QWIDGETSIZE_MAX. " + "Consider setting it to a less extreme value.", + minimumContentsLength); + } + } if (!placeholderText.isEmpty()) sh.setWidth(qMax(sh.width(), fm.boundingRect(placeholderText).width())); diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index e77fd804f21..bb05a94386b 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -297,6 +297,10 @@ void tst_QComboBox::getSetCheck() QCOMPARE(100, obj1.minimumContentsLength()); obj1.setMinimumContentsLength(INT_MIN); QCOMPARE(100, obj1.minimumContentsLength()); // Cannot be set to something negative => old value + QTest::ignoreMessage(QtWarningMsg, // not necessarily here, but upon first sizeHint() call + "QComboBox: cannot take minimumContentsLength 2147483647 into account for sizeHint(), " + "since it causes the widget to be wider than QWIDGETSIZE_MAX. " + "Consider setting it to a less extreme value."); obj1.setMinimumContentsLength(INT_MAX); QCOMPARE(INT_MAX, obj1.minimumContentsLength());