diff options
author | Wang Chuan <ouchuanm@outlook.com> | 2020-01-26 14:21:42 +0800 |
---|---|---|
committer | Wang Chuan <ouchuanm@outlook.com> | 2020-02-07 09:18:47 +0800 |
commit | 75285b64ada65748f1fee3942a95b46a3f0b9d7e (patch) | |
tree | 5e6fdf80a616ad2a64c05890c53033d6823b81c9 /tests/auto/widgets | |
parent | f9cd8fef5e9062f6bd23d70693f4dfb7e32efc78 (diff) |
QComboBox: send font change event to popup menu when font changed
The font change in QComboBox might cause incorrect appearance of popup
menu since it doesn't notify popup menu to relayout itself
Fixes the issue by send font change event to the item view of popup
menu when received a font change event in QComboBox
Fixes: QTBUG-75846
Change-Id: I4821015cca95a7e233a22262596a6fbf27f10aef
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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 <qtablewidget.h> #include <qscrollbar.h> #include <qboxlayout.h> +#include <qstackedwidget.h> #include <qstandarditemmodel.h> #include <qstringlistmodel.h> @@ -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" |