diff options
Diffstat (limited to 'src/widgets/styles/qstylehelper.cpp')
-rw-r--r-- | src/widgets/styles/qstylehelper.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index 5314ab1518..b4616b8c24 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -25,15 +25,26 @@ Q_GUI_EXPORT int qt_defaultDpiX(); namespace QStyleHelper { -QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size) +static inline bool usePixmapCache(const QStyleOption *opt) { + if (QWidget *widget = qobject_cast<QWidget *>(opt->styleObject)) + return !widget->testAttribute(Qt::WA_StyleSheetTarget); + return true; +} + +QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size, qreal dpr) +{ + if (!usePixmapCache(option)) + return {}; + const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option); QString tmp = key % HexString<uint>(option->state) % HexString<uint>(option->direction) % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u) % HexString<quint64>(option->palette.cacheKey()) % HexString<uint>(size.width()) - % HexString<uint>(size.height()); + % HexString<uint>(size.height()) + % HexString<qreal>(dpr); #if QT_CONFIG(spinbox) if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { @@ -89,7 +100,7 @@ Q_WIDGETS_EXPORT qreal dpiScaled(qreal value, const QStyleOption *option) return dpiScaled(value, dpi(option)); } -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) bool isInstanceOf(QObject *obj, QAccessible::Role role) { bool match = false; @@ -110,7 +121,7 @@ bool hasAncestor(QObject *obj, QAccessible::Role role) } return found; } -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) #if QT_CONFIG(dial) @@ -191,7 +202,7 @@ QPolygonF calcLines(const QStyleOptionSlider *dial) qreal xc = width / 2 + 0.5; qreal yc = height / 2 + 0.5; const int ns = dial->tickInterval; - if (!ns) // Invalid values may be set by Qt Designer. + if (!ns) // Invalid values may be set by Qt Widgets Designer. return poly; int notches = (dial->maximum + ns - 1 - dial->minimum) / ns; if (notches <= 0) @@ -226,7 +237,7 @@ QPolygonF calcLines(const QStyleOptionSlider *dial) void drawDial(const QStyleOptionSlider *option, QPainter *painter) { - QPalette pal = option->palette; + const QPalette pal = option->palette; QColor buttonColor = pal.button().color(); const int width = option->rect.width(); const int height = option->rect.height(); @@ -240,7 +251,11 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) // Draw notches if (option->subControls & QStyle::SC_DialTickmarks) { - painter->setPen(option->palette.dark().color().darker(120)); + const bool inverted = pal.window().color().lightness() < pal.text().color().lightness() + && pal.light().color().lightness() > pal.dark().color().lightness(); + const QColor notchColor = inverted ? pal.light().color().lighter(120) + : pal.dark().color().darker(120); + painter->setPen(notchColor); painter->drawLines(QStyleHelper::calcLines(option)); } |