From 42e0cf0c8a9df2788d9135753819af8e2e31e350 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Wed, 29 Dec 2021 21:49:00 -0600 Subject: [PATCH] [Spreadsheet] Use stylesheet for alias color When setting the text color for an invalid alias, use the Qt stylesheeet mechanism rather than QPalette, so that it works correctly with an applied QSS stylesheeet. Also attempt to detect a darkmode stylesheet and use lighter shade of red so that the alias is more legible. Finally, instead of explicitly setting the text color to black when it's valid, reset to the original stylesheet (usually an empty string). This ensures that in a dark stylesheet the text color is legible. Fixes #0004803. --- src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp index cc31540d45..4941fd22e5 100644 --- a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp +++ b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp @@ -419,7 +419,12 @@ void SheetView::aliasChanged(const QString& text) // check live the input and highlight if the user input invalid characters bool aliasOk = true; - QPalette palette = ui->cellAlias->palette(); + static auto originalStylesheet = ui->cellAlias->styleSheet(); + QString warningColor; + if (qApp->styleSheet().contains(QLatin1String("dark"), Qt::CaseInsensitive)) + warningColor = QLatin1String("rgb(255,90,90)"); // Light red for dark mode + else + warningColor = QLatin1String("rgb(200,0,0)"); // Dark red for light mode if (!text.isEmpty() && !sheet->isValidAlias(Base::Tools::toStdString(text))) aliasOk = false; @@ -427,16 +432,14 @@ void SheetView::aliasChanged(const QString& text) if (!aliasOk) { // change tooltip and make text color red ui->cellAlias->setToolTip(QObject::tr("Alias contains invalid characters!")); - palette.setColor(QPalette::Text, Qt::red); + ui->cellAlias->setStyleSheet(QLatin1String("color:") + warningColor); } else { // go back to normal ui->cellAlias->setToolTip( QObject::tr("Refer to cell by alias, for example\nSpreadsheet.my_alias_name instead of Spreadsheet.B1")); - palette.setColor(QPalette::Text, Qt::black); + ui->cellAlias->setStyleSheet(originalStylesheet); } - // apply the text color via the palette - ui->cellAlias->setPalette(palette); } void SheetView::currentChanged ( const QModelIndex & current, const QModelIndex & previous )