diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 9a0e969e1c..fdf1a87bba 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -3045,12 +3045,14 @@ void QComboBox::changeEvent(QEvent *e) d->updateViewContainerPaletteAndOpacity(); break; } - case QEvent::FontChange: + case QEvent::FontChange: { d->sizeHint = QSize(); // invalidate size hint d->viewContainer()->setFont(font()); + d->viewContainer()->itemView()->doItemsLayout(); if (d->lineEdit) d->updateLineEditGeometry(); break; + } default: break; } diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index b7869a0653..5ab59dce93 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -164,6 +165,7 @@ private slots: void task_QTBUG_56693_itemFontFromModel(); void inputMethodUpdate(); void task_QTBUG_52027_mapCompleterIndex(); + void checkMenuItemPosWhenStyleSheetIsSet(); private: PlatformInputContext m_platformInputContext; @@ -3466,5 +3468,46 @@ void tst_QComboBox::task_QTBUG_52027_mapCompleterIndex() QCOMPARE(arguments.at(0).toInt(), 1); } +void tst_QComboBox::checkMenuItemPosWhenStyleSheetIsSet() +{ + QString newCss = "QComboBox {font-size: 18pt;}"; + QString oldCss = qApp->styleSheet(); + qApp->setStyleSheet(newCss); + + QWidget topLevel; + QVBoxLayout *layout = new QVBoxLayout(&topLevel); + QStackedWidget *stack = new QStackedWidget(&topLevel); + layout->addWidget(stack); + QWidget *container = new QWidget(&topLevel); + QHBoxLayout *cLayout = new QHBoxLayout(container); + QComboBox *cBox = new QComboBox; + + QStandardItemModel *model = new QStandardItemModel(cBox); + QStandardItem *item = new QStandardItem(QStringLiteral("Item1")); + model->appendRow(item); + item = new QStandardItem(QStringLiteral("Item2")); + model->appendRow(item); + item = new QStandardItem(QStringLiteral("Item3")); + model->appendRow(item); + item = new QStandardItem(QStringLiteral("Item4")); + model->appendRow(item); + cBox->setModel(model); + + cLayout->addWidget(cBox); + stack->addWidget(container); + topLevel.show(); + cBox->showPopup(); + + QTRY_VERIFY(cBox->view()); + QTRY_VERIFY(cBox->view()->isVisible()); + + int menuHeight = cBox->view()->geometry().height(); + QRect menuItemRect = cBox->view()->visualRect(model->indexFromItem(item)); + + QCOMPARE(menuHeight, menuItemRect.y() + menuItemRect.height()); + + qApp->setStyleSheet(oldCss); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc"