From 730d07df831435d41d40152d5ecec5dea2658042 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 12 Jan 2015 21:08:13 +0100 Subject: 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 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/styles/qstylesheetstyle.cpp | 12 +++++++----- 1 file 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); -- cgit v1.2.3