summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2015-01-12 21:08:13 +0100
committerAndy Shaw <andy.shaw@digia.com>2015-01-19 10:44:48 +0100
commit730d07df831435d41d40152d5ecec5dea2658042 (patch)
tree0f8b902a4aa78696bfa6fd269cb83318c61984f2
parent17cce246487ca8a9b2d1999bfdbbb3b368b44177 (diff)
Account for pixmap's device pixel ratio when calculating the label size
When determining the size of the QPushButton's label then the device pixel ratio of the pixmap used to represent the icon needs to be taken into consideration so it is rendered correctly. Change-Id: If32760b120d7a749a51e2c30592d621c0e63dace Reviewed-by: Pierre Rossi <pierre.rossi@theqtcompany.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index e9f20de842..3d9ba6b490 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -3397,8 +3397,10 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
state = QIcon::On;
QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
- int labelWidth = pixmap.width();
- int labelHeight = pixmap.height();
+ 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())
@@ -3407,15 +3409,15 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
//Determine label alignment:
if (textAlignment & Qt::AlignLeft) { /*left*/
iconRect = QRect(textRect.x(), textRect.y() + (textRect.height() - labelHeight) / 2,
- pixmap.width(), pixmap.height());
+ pixmapWidth, pixmapHeight);
} else if (textAlignment & Qt::AlignHCenter) { /* center */
iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
textRect.y() + (textRect.height() - labelHeight) / 2,
- pixmap.width(), pixmap.height());
+ pixmapWidth, pixmapHeight);
} else { /*right*/
iconRect = QRect(textRect.x() + textRect.width() - labelWidth,
textRect.y() + (textRect.height() - labelHeight) / 2,
- pixmap.width(), pixmap.height());
+ pixmapWidth, pixmapHeight);
}
iconRect = visualRect(button->direction, textRect, iconRect);