QTextEdit::textColor - report the color QTextLayout will use

When 'foreground' in QTextCharFormat has style 'NoBrush', we are
using a different color, compared to what we are reporting as
text color - we use palette from QAbstractTextDocumentLayout::PaintContext.
So, in dark theme, we report the color black and then
paint the text using white color.

Fixes: QTBUG-127090
Change-Id: Ifef996c0867a6d189fffabd59c36136f9335220f
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Timur Pocheptsov 2024-08-15 16:06:39 +02:00
parent 1dd785d10d
commit 2a10a679a1

View File

@ -712,7 +712,14 @@ bool QTextEdit::fontItalic() const
QColor QTextEdit::textColor() const
{
Q_D(const QTextEdit);
return d->control->textCursor().charFormat().foreground().color();
const auto fg = d->control->textCursor().charFormat().foreground();
if (fg.style() == Qt::NoBrush) {
const auto context = d->control->getPaintContext(const_cast<QTextEdit *>(this));
return context.palette.color(QPalette::Text);
}
return fg.color();
}
/*!