Skip to content

Commit e5dfd0b

Browse files
committed
Views: do not set color to views which don't use our palette
1 parent 804939b commit e5dfd0b

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

style/adwaitastyle.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -409,28 +409,19 @@ void Style::polish(QWidget *widget)
409409

410410
#if QT_VERSION > 0x050000
411411
// HACK to avoid different text color in unfocused views
412+
// This has a side effect that the view will never grey out, but it's still better then having
413+
// views greyed out when the application is active
412414
if (QPointer<QAbstractItemView> view = qobject_cast<QAbstractItemView *>(widget)) {
413-
QWindow *win = widget ? widget->window()->windowHandle() : nullptr;
414-
if (win) {
415-
connect(win, &QWindow::activeChanged, this, [=] () {
416-
if (view.isNull()) {
417-
return;
418-
}
419-
420-
QPalette pal = view->palette();
421-
if (win->isActive()) {
422-
pal.setColor(QPalette::Inactive, QPalette::Text, pal.color(QPalette::Active, QPalette::Text));
423-
} else {
424-
polish(pal);
425-
}
426-
view->setPalette(pal);
427-
});
428-
429-
if (win->isActive()) {
430-
QMetaObject::invokeMethod(win, "activeChanged", Qt::QueuedConnection);
431-
}
415+
QPalette pal = view->palette();
416+
// TODO keep synced with the standard palette
417+
const QColor activeTextColor = _dark ? QColor("#eeeeec") : QColor("#2e3436");
418+
const QColor inactiveTextColor = _dark ? _helper->mix(QColor("#eeeeec"), _helper->darken(_helper->desaturate(QColor("#3d3846"), 1.0), 0.04)) :
419+
_helper->mix(QColor("#2e3436"), QColor("#f6f5f4"));
420+
// No custom text color used, we can do our HACK
421+
if (inactiveTextColor == pal.color(QPalette::Inactive, QPalette::Text) && activeTextColor == pal.color(QPalette::Active, QPalette::Text)) {
422+
pal.setColor(QPalette::Inactive, QPalette::Text, pal.color(QPalette::Active, QPalette::Text));
423+
view->setPalette(pal);
432424
}
433-
434425
}
435426
#endif
436427

@@ -4625,9 +4616,15 @@ bool Style::drawItemViewItemControl(const QStyleOption *option, QPainter *painte
46254616
#endif
46264617
#if QT_VERSION > 0x050000
46274618
if (_helper->isWindowActive(widget)) {
4619+
const QColor activeTextColor = _dark ? QColor("#eeeeec") : QColor("#2e3436");
4620+
const QColor inactiveTextColor = _dark ? _helper->mix(QColor("#eeeeec"), _helper->darken(_helper->desaturate(QColor("#3d3846"), 1.0), 0.04)) :
4621+
_helper->mix(QColor("#2e3436"), QColor("#f6f5f4"));
4622+
// No custom text color used, we can do our HACK
46284623
QPalette palette = op.palette;
4629-
palette.setColor(QPalette::Inactive, QPalette::Text, palette.color(QPalette::Active, QPalette::Text));
4630-
op.palette = palette;
4624+
if (inactiveTextColor == palette.color(QPalette::Inactive, QPalette::Text) && activeTextColor == palette.color(QPalette::Active, QPalette::Text)) {
4625+
palette.setColor(QPalette::Inactive, QPalette::Text, palette.color(QPalette::Active, QPalette::Text));
4626+
op.palette = palette;
4627+
}
46314628
}
46324629
#endif
46334630
ParentStyleClass::drawControl(CE_ItemViewItem, &op, painter, widget);

0 commit comments

Comments
 (0)