Make QStyle::itemPixmapRect handle devicePixelRatio
Layout sizes for images should be in the form QSize layoutSize = image.size() / image.devicePixelRatio() to be in device independent pixels Change-Id: Ic149144c45c8fa5c45ac5cbe2c82c35d721549cd Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
This commit is contained in:
parent
2cb17c1fb9
commit
d1ce29557c
@ -541,17 +541,21 @@ QRect QStyle::itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pi
|
|||||||
QRect result;
|
QRect result;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
rect.getRect(&x, &y, &w, &h);
|
rect.getRect(&x, &y, &w, &h);
|
||||||
|
|
||||||
|
const int pixmapWidth = pixmap.width()/pixmap.devicePixelRatio();
|
||||||
|
const int pixmapHeight = pixmap.height()/pixmap.devicePixelRatio();
|
||||||
|
|
||||||
if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
|
if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
|
||||||
y += h/2 - pixmap.height()/2;
|
y += h/2 - pixmapHeight/2;
|
||||||
else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
|
else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
|
||||||
y += h - pixmap.height();
|
y += h - pixmapHeight;
|
||||||
if ((alignment & Qt::AlignRight) == Qt::AlignRight)
|
if ((alignment & Qt::AlignRight) == Qt::AlignRight)
|
||||||
x += w - pixmap.width();
|
x += w - pixmapWidth;
|
||||||
else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
|
else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
|
||||||
x += w/2 - pixmap.width()/2;
|
x += w/2 - pixmapWidth/2;
|
||||||
else if ((alignment & Qt::AlignLeft) != Qt::AlignLeft && QApplication::isRightToLeft())
|
else if ((alignment & Qt::AlignLeft) != Qt::AlignLeft && QApplication::isRightToLeft())
|
||||||
x += w - pixmap.width();
|
x += w - pixmapWidth;
|
||||||
result = QRect(x, y, pixmap.width(), pixmap.height());
|
result = QRect(x, y, pixmapWidth, pixmapHeight);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user