QStyleHelper: pass devicePixelRatio to uniqueName()
QStyleHelper::uniqueName() took the size of the pixmap to cache but not the dpr. This might lead to a situation (e.g. in a multi-display environment) where we use a pixmap with the wrong dpr and get a pixelated result on the screen. Change-Id: Ifdebeddff3380931398b3284a7757b7da950caa9 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
This commit is contained in:
parent
c6c6dc471c
commit
896c4fe427
@ -759,7 +759,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
|
|||||||
const QString pixmapName = QStyleHelper::uniqueName("$qt_ia-"_L1
|
const QString pixmapName = QStyleHelper::uniqueName("$qt_ia-"_L1
|
||||||
% QLatin1StringView(metaObject()->className())
|
% QLatin1StringView(metaObject()->className())
|
||||||
% HexString<uint>(pe),
|
% HexString<uint>(pe),
|
||||||
opt, QSize(size, size) * pixelRatio);
|
opt, QSize(size, size), pixelRatio);
|
||||||
if (!QPixmapCache::find(pixmapName, &pixmap)) {
|
if (!QPixmapCache::find(pixmapName, &pixmap)) {
|
||||||
const qreal border = pixelRatio * (size / 5.);
|
const qreal border = pixelRatio * (size / 5.);
|
||||||
const qreal sqsize = pixelRatio * size;
|
const qreal sqsize = pixelRatio * size;
|
||||||
|
@ -157,7 +157,7 @@ static void qt_fusion_draw_arrow(Qt::ArrowType type, QPainter *painter, const QS
|
|||||||
const QString cacheKey = QStyleHelper::uniqueName("fusion-arrow"_L1
|
const QString cacheKey = QStyleHelper::uniqueName("fusion-arrow"_L1
|
||||||
% HexString<uint>(type)
|
% HexString<uint>(type)
|
||||||
% HexString<uint>(color.rgba()),
|
% HexString<uint>(color.rgba()),
|
||||||
option, rect.size());
|
option, rect.size(), dpr);
|
||||||
if (!QPixmapCache::find(cacheKey, &cachePixmap)) {
|
if (!QPixmapCache::find(cacheKey, &cachePixmap)) {
|
||||||
cachePixmap = styleCachePixmap(rect.size(), dpr);
|
cachePixmap = styleCachePixmap(rect.size(), dpr);
|
||||||
QPainter cachePainter(&cachePixmap);
|
QPainter cachePainter(&cachePixmap);
|
||||||
@ -1143,7 +1143,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
|
|||||||
% HexString(header->position)
|
% HexString(header->position)
|
||||||
% HexString(header->orientation)
|
% HexString(header->orientation)
|
||||||
% QLatin1Char(isSectionDragTarget ? '1' : '0'),
|
% QLatin1Char(isSectionDragTarget ? '1' : '0'),
|
||||||
option, option->rect.size());
|
option, option->rect.size(), dpr);
|
||||||
QPixmap cache;
|
QPixmap cache;
|
||||||
if (!QPixmapCache::find(pixmapName, &cache)) {
|
if (!QPixmapCache::find(pixmapName, &cache)) {
|
||||||
cache = styleCachePixmap(rect.size(), dpr);
|
cache = styleCachePixmap(rect.size(), dpr);
|
||||||
@ -1881,7 +1881,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
|
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
|
||||||
const qreal dpr = painter->device()->devicePixelRatio();
|
const qreal dpr = painter->device()->devicePixelRatio();
|
||||||
QPixmap cache;
|
QPixmap cache;
|
||||||
QString pixmapName = QStyleHelper::uniqueName("spinbox"_L1, spinBox, spinBox->rect.size());
|
QString pixmapName = QStyleHelper::uniqueName("spinbox"_L1, spinBox, spinBox->rect.size(), dpr);
|
||||||
if (!QPixmapCache::find(pixmapName, &cache)) {
|
if (!QPixmapCache::find(pixmapName, &cache)) {
|
||||||
|
|
||||||
cache = styleCachePixmap(spinBox->rect.size(), dpr);
|
cache = styleCachePixmap(spinBox->rect.size(), dpr);
|
||||||
@ -2583,7 +2583,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
% QLatin1StringView(comboBox->editable ? "-editable" : "")
|
% QLatin1StringView(comboBox->editable ? "-editable" : "")
|
||||||
% QLatin1StringView(isEnabled ? "-enabled" : "")
|
% QLatin1StringView(isEnabled ? "-enabled" : "")
|
||||||
% QLatin1StringView(!comboBox->frame ? "-frameless" : ""),
|
% QLatin1StringView(!comboBox->frame ? "-frameless" : ""),
|
||||||
option, comboBox->rect.size());
|
option, comboBox->rect.size(), dpr);
|
||||||
if (!QPixmapCache::find(pixmapName, &cache)) {
|
if (!QPixmapCache::find(pixmapName, &cache)) {
|
||||||
cache = styleCachePixmap(comboBox->rect.size(), dpr);
|
cache = styleCachePixmap(comboBox->rect.size(), dpr);
|
||||||
QPainter cachePainter(&cache);
|
QPainter cachePainter(&cache);
|
||||||
@ -2695,7 +2695,8 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
grooveColor.setHsv(buttonColor.hue(),
|
grooveColor.setHsv(buttonColor.hue(),
|
||||||
qMin(255, (int)(buttonColor.saturation())),
|
qMin(255, (int)(buttonColor.saturation())),
|
||||||
qMin(255, (int)(buttonColor.value()*0.9)));
|
qMin(255, (int)(buttonColor.value()*0.9)));
|
||||||
QString groovePixmapName = QStyleHelper::uniqueName("slider_groove"_L1, option, groove.size());
|
QString groovePixmapName = QStyleHelper::uniqueName("slider_groove"_L1, option,
|
||||||
|
groove.size(), dpr);
|
||||||
QRect pixmapRect(0, 0, groove.width(), groove.height());
|
QRect pixmapRect(0, 0, groove.width(), groove.height());
|
||||||
|
|
||||||
// draw background groove
|
// draw background groove
|
||||||
@ -2838,7 +2839,8 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
}
|
}
|
||||||
// draw handle
|
// draw handle
|
||||||
if ((option->subControls & SC_SliderHandle) ) {
|
if ((option->subControls & SC_SliderHandle) ) {
|
||||||
QString handlePixmapName = QStyleHelper::uniqueName("slider_handle"_L1, option, handle.size());
|
QString handlePixmapName = QStyleHelper::uniqueName("slider_handle"_L1, option,
|
||||||
|
handle.size(), dpr);
|
||||||
if (!QPixmapCache::find(handlePixmapName, &cache)) {
|
if (!QPixmapCache::find(handlePixmapName, &cache)) {
|
||||||
cache = styleCachePixmap(handle.size(), dpr);
|
cache = styleCachePixmap(handle.size(), dpr);
|
||||||
QRect pixmapRect(0, 0, handle.width(), handle.height());
|
QRect pixmapRect(0, 0, handle.width(), handle.height());
|
||||||
|
@ -48,7 +48,7 @@ inline QPixmap styleCachePixmap(const QSize &size, qreal pixelRatio)
|
|||||||
QPixmap internalPixmapCache; \
|
QPixmap internalPixmapCache; \
|
||||||
QPainter *p = painter; \
|
QPainter *p = painter; \
|
||||||
const auto dpr = p->device()->devicePixelRatio(); \
|
const auto dpr = p->device()->devicePixelRatio(); \
|
||||||
const QString unique = QStyleHelper::uniqueName((a), option, option->rect.size()); \
|
const QString unique = QStyleHelper::uniqueName((a), option, option->rect.size(), dpr); \
|
||||||
int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \
|
int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \
|
||||||
const bool doPixmapCache = (!option->rect.isEmpty()) \
|
const bool doPixmapCache = (!option->rect.isEmpty()) \
|
||||||
&& ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \
|
&& ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \
|
||||||
|
@ -32,7 +32,7 @@ static inline bool usePixmapCache(const QStyleOption *opt)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size)
|
QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size, qreal dpr)
|
||||||
{
|
{
|
||||||
if (!usePixmapCache(option))
|
if (!usePixmapCache(option))
|
||||||
return {};
|
return {};
|
||||||
@ -43,7 +43,8 @@ QString uniqueName(const QString &key, const QStyleOption *option, const QSize &
|
|||||||
% HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u)
|
% HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u)
|
||||||
% HexString<quint64>(option->palette.cacheKey())
|
% HexString<quint64>(option->palette.cacheKey())
|
||||||
% HexString<uint>(size.width())
|
% HexString<uint>(size.width())
|
||||||
% HexString<uint>(size.height());
|
% HexString<uint>(size.height())
|
||||||
|
% HexString<qreal>(dpr);
|
||||||
|
|
||||||
#if QT_CONFIG(spinbox)
|
#if QT_CONFIG(spinbox)
|
||||||
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
|
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
|
||||||
|
@ -39,7 +39,7 @@ class QWindow;
|
|||||||
|
|
||||||
namespace QStyleHelper
|
namespace QStyleHelper
|
||||||
{
|
{
|
||||||
QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size);
|
QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size, qreal dpr);
|
||||||
|
|
||||||
Q_WIDGETS_EXPORT qreal dpi(const QStyleOption *option);
|
Q_WIDGETS_EXPORT qreal dpi(const QStyleOption *option);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user