From 5cff7d2b679d48a247b4630cb9e3d5b04fab0b55 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 31 Oct 2016 11:54:51 -0700 Subject: QComboBox: Prioritize the model font for popup items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Mac, we use QComboMenuDelegate specifically as item delegate for the popup list. It happens that the order of resolving the font for each item individually would prioritize QComboBox's font instead of whatever the assigned model's FontRole would specify. The fix only requires checking whether FontRole is valid before falling back QComboBox's properties. Change-Id: I7208ad1911b30cc52c826c1884a1e19f5acd9fb4 Task-number: QTBUG-56693 Reviewed-by: Morten Johan Sørvig --- src/widgets/widgets/qcombobox.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 52e7962109..4358e568bf 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -170,18 +170,18 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt menuOption.menuRect = option.rect; menuOption.rect = option.rect; - // Make sure fonts set on the combo box also overrides the font for the popup menu. - if (mCombo->testAttribute(Qt::WA_SetFont) + // Make sure fonts set on the model or on the combo box, in + // that order, also override the font for the popup menu. + QVariant fontRoleData = index.data(Qt::FontRole); + if (fontRoleData.isValid()) { + menuOption.font = fontRoleData.value(); + } else if (mCombo->testAttribute(Qt::WA_SetFont) || mCombo->testAttribute(Qt::WA_MacSmallSize) || mCombo->testAttribute(Qt::WA_MacMiniSize) || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) { menuOption.font = mCombo->font(); } else { - QVariant fontRoleData = index.data(Qt::FontRole); - if (fontRoleData.isValid()) - menuOption.font = fontRoleData.value(); - else - menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font()); + menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font()); } menuOption.fontMetrics = QFontMetrics(menuOption.font); -- cgit v1.2.3