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 <richard.gustavsen@qt.io>
bb10
Andy Shaw 2020-08-17 14:53:39 +02:00
parent 7e10dcb1d4
commit c3f74bdc3f
1 changed files with 3 additions and 3 deletions

View File

@ -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))