[Gui] Make styles update on paint (#17376)

* [Gui] Make styles update on paint

Fixes #15756. Similar implementation to that already in FileCardDelegate.cpp

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Benjamin Bræstrup Sayoc
2024-10-28 16:48:47 +01:00
committed by GitHub
parent f4aed92df4
commit ff28df61f1
6 changed files with 40 additions and 38 deletions

View File

@@ -112,46 +112,50 @@ void FileCardDelegate::paint(QPainter* painter,
thumbnail->setFixedSize(thumbnailSize, thumbnailSize);
thumbnail->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
QString style = QStringLiteral("");
_widget->setProperty("state", QStringLiteral(""));
if (option.state & QStyle::State_Selected) {
_widget->setProperty("state", QStringLiteral("pressed"));
if (qApp->styleSheet().isEmpty()) {
QColor color = getSelectionColor();
_widget->setStyleSheet(QString::fromLatin1("QWidget#thumbnailWidget {"
" border: 2px solid rgb(%1, %2, %3);"
" border-radius: 4px;"
" padding: 2px;"
"}")
.arg(color.red())
.arg(color.green())
.arg(color.blue()));
style = QString::fromLatin1("QWidget#thumbnailWidget {"
" border: 2px solid rgb(%1, %2, %3);"
" border-radius: 4px;"
" padding: 2px;"
"}")
.arg(color.red())
.arg(color.green())
.arg(color.blue());
}
}
else if (option.state & QStyle::State_MouseOver) {
_widget->setProperty("state", QStringLiteral("hovered"));
if (qApp->styleSheet().isEmpty()) {
QColor color = getBorderColor();
_widget->setStyleSheet(QString::fromLatin1("QWidget#thumbnailWidget {"
" border: 2px solid rgb(%1, %2, %3);"
" border-radius: 4px;"
" padding: 2px;"
"}")
.arg(color.red())
.arg(color.green())
.arg(color.blue()));
style = QString::fromLatin1("QWidget#thumbnailWidget {"
" border: 2px solid rgb(%1, %2, %3);"
" border-radius: 4px;"
" padding: 2px;"
"}")
.arg(color.red())
.arg(color.green())
.arg(color.blue());
}
}
else if (qApp->styleSheet().isEmpty()) {
QColor color = getBackgroundColor();
_widget->setStyleSheet(QString::fromLatin1("QWidget#thumbnailWidget {"
" background-color: rgb(%1, %2, %3);"
" border-radius: 8px;"
"}")
.arg(color.red())
.arg(color.green())
.arg(color.blue()));
style = QString::fromLatin1("QWidget#thumbnailWidget {"
" background-color: rgb(%1, %2, %3);"
" border-radius: 8px;"
"}")
.arg(color.red())
.arg(color.green())
.arg(color.blue());
}
_widget->setStyleSheet(style);
auto elided =
painter->fontMetrics().elidedText(baseName, Qt::TextElideMode::ElideRight, cardWidth);
auto name = std::make_unique<QLabel>(elided);