diff options
author | Axel Spoerl <axel.spoerl@qt.io> | 2023-05-18 11:15:43 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-22 14:45:26 +0000 |
commit | 980a499ad0a4d30806d8c40e89b8d06419915a77 (patch) | |
tree | 20697c529bf5ccddce7c7bbf2034698bfbc254fb /src/widgets | |
parent | 227b639499d7e9ebabd6e07e80f2c5c63a6a2154 (diff) |
Implement color role AccentColor in QStyleSheetStyle and QCssParser
The color role AccentColor has been added to QPalette.
This patch implements the new color role in QCssParser and subsequently
in QStyleSheetStyle.
The QBrush variable names used to populate brushes, have been changed
into speaking names for better code readability.
tst_QCssParser has been adapted accordingly.
The test function accentColor() has been added in tst_QStyleSheetStyle.
Documentation has been updated.
Change-Id: Ib09ddc1b61868f2bb8f70f654e83ea1c35276d30
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc | 8 | ||||
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 35 |
2 files changed, 35 insertions, 8 deletions
diff --git a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc index 0115285454..5315fe85d4 100644 --- a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc +++ b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc @@ -1358,6 +1358,13 @@ \li Description \row + \li \b{\c accent-color} + \li \l{#Brush}{Brush} \br + \li The property sets the \c AccentColor, which is used to emphasize + interactive UI elements. + If this property is not set, it defaults to the \c highlight color. + + \row \li \b{\c alternate-background-color} \target alternate-background-color-prop \li \l{#Brush}{Brush} \br \li The \l{QAbstractItemView::alternatingRowColors} @@ -3064,6 +3071,7 @@ \row \li \b{PaletteRole} \target PaletteRole \li \c alternate-base \br + | \c accentColor \br | \c base \br | \c bright-text \br | \c button \br diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index c2a720c433..5d0432d2e0 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -434,16 +434,26 @@ struct QStyleSheetBoxData : public QSharedData struct QStyleSheetPaletteData : public QSharedData { - QStyleSheetPaletteData(const QBrush &fg, const QBrush &sfg, const QBrush &sbg, - const QBrush &abg, const QBrush &pfg) - : foreground(fg), selectionForeground(sfg), selectionBackground(sbg), - alternateBackground(abg), placeholderForeground(pfg) { } + QStyleSheetPaletteData(const QBrush &foreground, + const QBrush &selectedForeground, + const QBrush &selectedBackground, + const QBrush &alternateBackground, + const QBrush &placeHolderTextForeground, + const QBrush &accentColor) + : foreground(foreground) + , selectionForeground(selectedForeground) + , selectionBackground(selectedBackground) + , alternateBackground(alternateBackground) + , placeholderForeground(placeHolderTextForeground) + , accentColor(accentColor) + { } QBrush foreground; QBrush selectionForeground; QBrush selectionBackground; QBrush alternateBackground; QBrush placeholderForeground; + QBrush accentColor; }; struct QStyleSheetGeometryData : public QSharedData @@ -955,10 +965,17 @@ QRenderRule::QRenderRule(const QList<Declaration> &declarations, const QObject * bg = new QStyleSheetBackgroundData(brush, pixmap, repeat, alignment, origin, attachment, clip); } - QBrush sfg, fg, pfg; - QBrush sbg, abg; - if (v.extractPalette(&fg, &sfg, &sbg, &abg, &pfg)) - pal = new QStyleSheetPaletteData(fg, sfg, sbg, abg, pfg); + QBrush foreground; + QBrush selectedForeground; + QBrush selectedBackground; + QBrush alternateBackground; + QBrush placeHolderTextForeground; + QBrush accentColor; + if (v.extractPalette(&foreground, &selectedForeground, &selectedBackground, + &alternateBackground, &placeHolderTextForeground, &accentColor)) { + pal = new QStyleSheetPaletteData(foreground, selectedForeground, selectedBackground, + alternateBackground, placeHolderTextForeground, accentColor); + } QIcon imgIcon; alignment = Qt::AlignCenter; @@ -1487,6 +1504,8 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q p->setBrush(cg, QPalette::AlternateBase, pal->alternateBackground); if (pal->placeholderForeground.style() != Qt::NoBrush) p->setBrush(cg, QPalette::PlaceholderText, pal->placeholderForeground); + if (pal->accentColor.style() != Qt::NoBrush) + p->setBrush(cg, QPalette::AccentColor, pal->accentColor); } bool QRenderRule::hasModification() const |