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>
This commit is contained in:
parent
17cce24648
commit
730d07df83
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user