StyleSheetStyle: Fix color of placeholder texts in text edits
Prior to 5.12, the placeholder text color was hardcoded to be the same as the text color, but with an alpha of 128, i.e. semi-transparent. In 5.12, it instead got its own ColorRole in QPalette. So behavior changed (In some cases in 5.12 and later, consistently from Qt 6): placeholder texts no longer got a "light" (semi-transparent) version of the css-styled color, but just the default gray/semi-transparent black. That problem was reported as QTBUG-89815. However, the fix for that bug did not apply the semi-transparency, but only used the same color as the text. That caused a confusing visual expression, as actual and placeholder text would look the same. This commit fixes that. The problem was made worse since there is no way to specify the placeholder text color from css, i.e. to style it independently. A follow up commit will aim to add that. Fixes: QTBUG-92199 Task-number: QTBUG-93009 Pick-to: 6.4 6.2 5.15 Change-Id: I9e6698d34eba91cbf65c4da07aa5ac6d9f96a9ed Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
491dc83bbf
commit
df0b70eece
@ -1474,7 +1474,11 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q
|
||||
p->setBrush(cg, w->foregroundRole(), pal->foreground);
|
||||
p->setBrush(cg, QPalette::WindowText, pal->foreground);
|
||||
p->setBrush(cg, QPalette::Text, pal->foreground);
|
||||
p->setBrush(cg, QPalette::PlaceholderText, pal->foreground);
|
||||
QColor phColor(pal->foreground.color());
|
||||
phColor.setAlpha((phColor.alpha() + 1) / 2);
|
||||
QBrush placeholder = pal->foreground;
|
||||
placeholder.setColor(phColor);
|
||||
p->setBrush(cg, QPalette::PlaceholderText, placeholder);
|
||||
}
|
||||
if (pal->selectionBackground.style() != Qt::NoBrush)
|
||||
p->setBrush(cg, QPalette::Highlight, pal->selectionBackground);
|
||||
|
@ -2341,11 +2341,19 @@ void tst_QStyleSheetStyle::placeholderColor()
|
||||
QLineEdit le2;
|
||||
le2.setEnabled(false);
|
||||
le1.ensurePolished();
|
||||
QCOMPARE(le1.palette().placeholderText(), red);
|
||||
QColor phColor = le1.palette().placeholderText().color();
|
||||
QCOMPARE(phColor.rgb(), red.rgb());
|
||||
QVERIFY(phColor.alpha() < red.alpha());
|
||||
|
||||
le2.ensurePolished();
|
||||
QCOMPARE(le2.palette().placeholderText(), red);
|
||||
phColor = le2.palette().placeholderText().color();
|
||||
QCOMPARE(phColor.rgb(), red.rgb());
|
||||
QVERIFY(phColor.alpha() < red.alpha());
|
||||
|
||||
le2.setEnabled(true);
|
||||
QCOMPARE(le2.palette().placeholderText(), red);
|
||||
phColor = le2.palette().placeholderText().color();
|
||||
QCOMPARE(phColor.rgb(), red.rgb());
|
||||
QVERIFY(phColor.alpha() < red.alpha());
|
||||
}
|
||||
|
||||
void tst_QStyleSheetStyle::enumPropertySelector_data()
|
||||
|
Loading…
Reference in New Issue
Block a user