diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 26ab28d23b..3305c68144 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3704,12 +3704,14 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q act = opt->state & QStyle::State_Selected; int checkableOffset = 0; + int checkableWidth = 0; if (checkable) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QStyleOptionMenuItem newMi = mi; newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); + checkableWidth = newMi.rect.width(); // align with icons if there are some - checkableOffset = std::max(m->maxIconWidth, newMi.rect.width()); + checkableOffset = qMax(m->maxIconWidth, checkableWidth); if (subSubRule.hasDrawable() || checked) drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); } @@ -3744,7 +3746,12 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q if (subRule.hasBox() && subRule.box()->paddings[LeftEdge] == 0) { textOffset = checkableOffset; if (!m->icon.isNull() || !checkable) - textOffset += m->maxIconWidth; + textOffset += m->maxIconWidth; + } + else { + // Add extra offset if both a check and icon is present + if (!m->icon.isNull() && checkable) + textOffset += qMin(m->maxIconWidth, checkableWidth); } QRect textRect = subRule.contentsRect(opt->rect); textRect.setLeft(textRect.left() + textOffset); @@ -5095,7 +5102,7 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op sz.rwidth() += std::max(mi->maxIconWidth, checkmarkRect.width()); } if (!mi->icon.isNull() || !checkable) - sz.rwidth() += mi->maxIconWidth; + sz.rwidth() += mi->maxIconWidth; if (subRule.hasFont) { QFontMetrics fm(subRule.font); const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text);