Derive PlaceholderText color from Text color in QPalette
Until Qt 5.15, PlaceholderText color was automatically derived from the Text color, dimmed by 50% (set alpha to 128, assuming the text color is fully opaque). This method has been adapted in the static qt_fusionPalette() method. No other static method to populate palettes defines a PlaceholderText color. As a consequence, the Text color is used to render placeholder text characters. This patch adds a static method, that sets missing PlaceholderText colors by deriving them from the corresponding Text color. It takes a dim factor by which the opacity is reduced versus the corresponding Text color. Fixes: QTBUG-105049 Pick-to: 6.4 6.3 6.2 Change-Id: Iebb9d15d56f5d72d7ec68b7a0babdf5825b92665 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
parent
4fdadd2348
commit
ebf733c6fb
@ -60,6 +60,34 @@ static QColor qt_mix_colors(QColor a, QColor b)
|
||||
(a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Derive undefined \l PlaceholderText colors from \l Text colors.
|
||||
Unless already set, PlaceholderText colors will be derived from their Text pendents.
|
||||
Colors of existing PlaceHolderText brushes will not be replaced.
|
||||
|
||||
\a alpha represents the dim factor as a percentage. By default, a PlaceHolderText color
|
||||
becomes a 50% more transparent version of the corresponding Text color.
|
||||
*/
|
||||
static void qt_placeholder_from_text(QPalette &pal, int alpha = 50)
|
||||
{
|
||||
if (alpha < 0 or alpha > 100)
|
||||
return;
|
||||
|
||||
for (int cg = 0; cg < int(QPalette::NColorGroups); ++cg) {
|
||||
const QPalette::ColorGroup group = QPalette::ColorGroup(cg);
|
||||
|
||||
// skip if the brush has been set already
|
||||
if (!pal.isBrushSet(group, QPalette::PlaceholderText)) {
|
||||
QColor c = pal.color(group, QPalette::Text);
|
||||
const int a = (c.alpha() * alpha) / 100;
|
||||
c.setAlpha(a);
|
||||
pal.setColor(group, QPalette::PlaceholderText, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void qt_palette_from_color(QPalette &pal, const QColor &button)
|
||||
{
|
||||
int h, s, v;
|
||||
@ -82,6 +110,8 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
|
||||
pal.setColorGroup(QPalette::Disabled, buttonBrushDark, buttonBrush, buttonBrushLight150,
|
||||
buttonBrushDark, buttonBrushDark150, buttonBrushDark,
|
||||
whiteBrush, buttonBrush, buttonBrush);
|
||||
|
||||
qt_placeholder_from_text(pal);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -569,6 +599,8 @@ QPalette::QPalette(const QBrush &windowText, const QBrush &button,
|
||||
init();
|
||||
setColorGroup(All, windowText, button, light, dark, mid, text, bright_text,
|
||||
base, window);
|
||||
|
||||
qt_placeholder_from_text(*this);
|
||||
}
|
||||
|
||||
|
||||
@ -624,6 +656,8 @@ QPalette::QPalette(const QColor &button, const QColor &window)
|
||||
setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150,
|
||||
buttonBrushDark, buttonBrushDark150, disabledForeground,
|
||||
whiteBrush, baseBrush, windowBrush);
|
||||
|
||||
qt_placeholder_from_text(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user