From c3f74bdc3ffdc69dce17530f9fafb2d6d15b746b Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 17 Aug 2020 14:53:39 +0200 Subject: Don't crop the icon when it is aligned to the left When we use double the icon spacing then the area for the pushbutton is not long enough, so in order to account for the gap inbetween then just use half of the icon spacing when positioning the text as it only has spacing on one side of the icon to it. Change-Id: Ib3fe0037835b67efda0fc274421f976ccc98eb06 Pick-to: 5.15 Fixes: QTBUG-85723 Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qcommonstyle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index bb646accf6..3f86320c5d 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1379,7 +1379,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint() if (!button->text.isEmpty()) { int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width(); - labelWidth += (textWidth + iconSpacing * 2); + labelWidth += (textWidth + iconSpacing); } QRect iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2, @@ -1390,10 +1390,10 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (button->direction == Qt::RightToLeft) { tf |= Qt::AlignRight; - textRect.setRight(iconRect.left() - iconSpacing); + textRect.setRight(iconRect.left() - iconSpacing / 2); } else { tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead - textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing); + textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing / 2); } if (button->state & (State_On | State_Sunken)) -- cgit v1.2.3