diff --git a/src/FrameworkWidgetFactory.cpp b/src/FrameworkWidgetFactory.cpp index 66c8c228..01ac256d 100644 --- a/src/FrameworkWidgetFactory.cpp +++ b/src/FrameworkWidgetFactory.cpp @@ -252,25 +252,15 @@ QIcon DefaultWidgetFactory::iconForButtonType(TitleBarButtonType type, qreal dpr return {}; QIcon icon(QStringLiteral(":/img/%1.png").arg(iconName)); - -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) - const bool isFractional = int(dpr) != dpr; - if (isFractional) { - // We don't support 1.5x yet. - // Problem with Linux is that rendering is off due to a rounding bug only fixed in 5.15.2 - // Will enable for fractional later. - // QTBUG-86170 - // Mostly affects Linux. Unless you're using Qt::HighDpiScaleFactorRoundingPolicy::PassThrough, in which case it will - // affect other OSes too. + if (!scalingFactorIsSupported(dpr)) return icon; - } -#else + // Not using Qt's sugar syntax, which doesn't support 1.5x anyway when we need it. // Simply add the high-res files and Qt will pick them when needed - icon.addFile(QStringLiteral(":/img/%1-1.5x.png").arg(iconName)); - Q_UNUSED(dpr); -#endif + if (scalingFactorIsSupported(1.5)) + icon.addFile(QStringLiteral(":/img/%1-1.5x.png").arg(iconName)); + icon.addFile(QStringLiteral(":/img/%1-2x.png").arg(iconName)); return icon; diff --git a/src/private/Utils_p.h b/src/private/Utils_p.h index ee43c3b9..9fd46e35 100644 --- a/src/private/Utils_p.h +++ b/src/private/Utils_p.h @@ -325,6 +325,21 @@ inline QRect globalGeometry(QWidgetOrQuick *w) return geo; } +/// @brief Returns whether we support the specified scalling factor +/// This is a workaround against a bug in older Qt (QTBUG-86170). +/// Mostly affects Linux. Unless you're using Qt::HighDpiScaleFactorRoundingPolicy::PassThrough, in which case it will affect other OSes too. +inline bool scalingFactorIsSupported(qreal factor) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) + // We don't support fractional factors in older Qt. + const bool isInteger = int(factor) == factor; + return isInteger; +#else + Q_UNUSED(factor); + return true; +#endif +} + }; #endif