summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qcommonstyle.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-12-10 13:51:40 +0200
committerLiang Qi <liang.qi@qt.io>2019-12-10 13:51:40 +0200
commit90210d5d9c4029057035019f144212922494ff0a (patch)
tree1aacefa57786964d47a200791280ae91c9b825da /src/widgets/styles/qcommonstyle.cpp
parentc69a2448ab129d88411a4778f2350dcf971dc623 (diff)
parent5231c26a82a7056f98d99643850754d4e1ebe417 (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts: tests/auto/network/kernel/qnetworkinterface/BLACKLIST Change-Id: I1e8866c63b54bcd95fc2a044276ee15b7f60e79a
Diffstat (limited to 'src/widgets/styles/qcommonstyle.cpp')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 6b3e3679ae..03081658bb 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -1363,7 +1363,6 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (!button->icon.isNull()) {
//Center both icon and text
- QRect iconRect;
QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
if (mode == QIcon::Normal && button->state & State_HasFocus)
mode = QIcon::Active;
@@ -1372,28 +1371,29 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
state = QIcon::On;
QPixmap pixmap = button->icon.pixmap(qt_getWindow(widget), button->iconSize, mode, state);
-
int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
int labelWidth = pixmapWidth;
int labelHeight = pixmapHeight;
int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint()
- int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
- if (!button->text.isEmpty())
+ if (!button->text.isEmpty()) {
+ int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
labelWidth += (textWidth + iconSpacing);
+ }
- iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
- textRect.y() + (textRect.height() - labelHeight) / 2,
- pixmapWidth, pixmapHeight);
+ QRect iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
+ textRect.y() + (textRect.height() - labelHeight) / 2,
+ pixmapWidth, pixmapHeight);
iconRect = visualRect(button->direction, textRect, iconRect);
- tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead
-
- if (button->direction == Qt::RightToLeft)
+ if (button->direction == Qt::RightToLeft) {
+ tf |= Qt::AlignRight;
textRect.setRight(iconRect.left() - iconSpacing);
- else
+ } else {
+ tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead
textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing);
+ }
if (button->state & (State_On | State_Sunken))
iconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),