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>
This commit is contained in:
parent
f9cd8fef5e
commit
75285b64ad
@ -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;
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user