Widget/StylesheetStyle: don't draw checkmarks for combobox dropdown
The combobox dropdown items are drawn as CE_MenuItem elements. Those elements may have a checkmarks but not when we draw them within a QComboMenuDelegate. Therefore add the same check as for fusion style to avoid drawing a checkmark in a QComboBox dropdown menu. Fixes: QTBUG-127536 Change-Id: Ib22046b018fdf36eb26518899d2427d40b0110b8 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit c2d56961394cea799b0caa241c3517ed88aa6c66) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2622b7f602
commit
cd34e5c7ba
@ -3923,10 +3923,16 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
|
|||||||
}
|
}
|
||||||
mi.palette.setBrush(QPalette::HighlightedText, mi.palette.brush(QPalette::ButtonText));
|
mi.palette.setBrush(QPalette::HighlightedText, mi.palette.brush(QPalette::ButtonText));
|
||||||
|
|
||||||
int textRectOffset = m->maxIconWidth;
|
bool drawCheckMark = mi.menuHasCheckableItems;
|
||||||
|
#if QT_CONFIG(combobox)
|
||||||
|
if (qobject_cast<const QComboBox *>(w))
|
||||||
|
drawCheckMark = false; // ignore the checkmarks provided by the QComboMenuDelegate
|
||||||
|
#endif
|
||||||
|
int textRectOffset = 0;
|
||||||
if (!mi.icon.isNull()) {
|
if (!mi.icon.isNull()) {
|
||||||
renderMenuItemIcon(&mi, p, w, opt->rect, subRule);
|
renderMenuItemIcon(&mi, p, w, opt->rect, subRule);
|
||||||
} else if (mi.menuHasCheckableItems) {
|
textRectOffset = m->maxIconWidth;
|
||||||
|
} else if (drawCheckMark) {
|
||||||
const bool checkable = mi.checkType != QStyleOptionMenuItem::NotCheckable;
|
const bool checkable = mi.checkType != QStyleOptionMenuItem::NotCheckable;
|
||||||
const bool checked = checkable ? mi.checked : false;
|
const bool checked = checkable ? mi.checked : false;
|
||||||
|
|
||||||
@ -3941,7 +3947,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
|
|||||||
newMi.rect = cmRect;
|
newMi.rect = cmRect;
|
||||||
drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
|
drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
|
||||||
}
|
}
|
||||||
textRectOffset = std::max(textRectOffset, cmRect.width());
|
textRectOffset = std::max(m->maxIconWidth, cmRect.width());
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect textRect = subRule.contentsRect(opt->rect);
|
QRect textRect = subRule.contentsRect(opt->rect);
|
||||||
@ -5421,6 +5427,11 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
|
|||||||
return QSize(sz.width(), subRule.size().height());
|
return QSize(sz.width(), subRule.size().height());
|
||||||
}
|
}
|
||||||
if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder() || subRule.hasFont)) {
|
if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder() || subRule.hasFont)) {
|
||||||
|
bool drawCheckMark = mi->menuHasCheckableItems;
|
||||||
|
#if QT_CONFIG(combobox)
|
||||||
|
if (qobject_cast<const QComboBox *>(w))
|
||||||
|
drawCheckMark = false; // ignore the checkmarks provided by the QComboMenuDelegate
|
||||||
|
#endif
|
||||||
QSize sz(csz);
|
QSize sz(csz);
|
||||||
if (mi->text.contains(u'\t'))
|
if (mi->text.contains(u'\t'))
|
||||||
sz.rwidth() += 12; //as in QCommonStyle
|
sz.rwidth() += 12; //as in QCommonStyle
|
||||||
@ -5428,7 +5439,7 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
|
|||||||
const int pmSmall = pixelMetric(PM_SmallIconSize);
|
const int pmSmall = pixelMetric(PM_SmallIconSize);
|
||||||
const QSize pmSize = mi->icon.actualSize(QSize(pmSmall, pmSmall));
|
const QSize pmSize = mi->icon.actualSize(QSize(pmSmall, pmSmall));
|
||||||
sz.rwidth() += std::max(mi->maxIconWidth, pmSize.width()) + 4;
|
sz.rwidth() += std::max(mi->maxIconWidth, pmSize.width()) + 4;
|
||||||
} else if (mi->menuHasCheckableItems) {
|
} else if (drawCheckMark) {
|
||||||
QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark);
|
QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark);
|
||||||
QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction);
|
QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction);
|
||||||
sz.rwidth() += std::max(mi->maxIconWidth, checkmarkRect.width()) + 4;
|
sz.rwidth() += std::max(mi->maxIconWidth, checkmarkRect.width()) + 4;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user