Skip to content

Commit 4098c88

Browse files
committed
[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 #4803.
1 parent 7b3c3e6 commit 4098c88

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,24 +419,27 @@ void SheetView::aliasChanged(const QString& text)
419419
// check live the input and highlight if the user input invalid characters
420420

421421
bool aliasOk = true;
422-
QPalette palette = ui->cellAlias->palette();
422+
static auto originalStylesheet = ui->cellAlias->styleSheet();
423+
QString warningColor;
424+
if (qApp->styleSheet().contains(QLatin1String("dark"), Qt::CaseInsensitive))
425+
warningColor = QLatin1String("rgb(255,90,90)"); // Light red for dark mode
426+
else
427+
warningColor = QLatin1String("rgb(200,0,0)"); // Dark red for light mode
423428

424429
if (!text.isEmpty() && !sheet->isValidAlias(Base::Tools::toStdString(text)))
425430
aliasOk = false;
426431

427432
if (!aliasOk) {
428433
// change tooltip and make text color red
429434
ui->cellAlias->setToolTip(QObject::tr("Alias contains invalid characters!"));
430-
palette.setColor(QPalette::Text, Qt::red);
435+
ui->cellAlias->setStyleSheet(QLatin1String("color:") + warningColor);
431436
}
432437
else {
433438
// go back to normal
434439
ui->cellAlias->setToolTip(
435440
QObject::tr("Refer to cell by alias, for example\nSpreadsheet.my_alias_name instead of Spreadsheet.B1"));
436-
palette.setColor(QPalette::Text, Qt::black);
441+
ui->cellAlias->setStyleSheet(originalStylesheet);
437442
}
438-
// apply the text color via the palette
439-
ui->cellAlias->setPalette(palette);
440443
}
441444

442445
void SheetView::currentChanged ( const QModelIndex & current, const QModelIndex & previous )

0 commit comments

Comments
 (0)