Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ee096b1

Browse files
committedJan 24, 2022
Workaround broken inactive window coloring applies incorrectly
to list/tree/dock widgets in the active window This is a theming issue which is apparent on certain default Linux themes, e.g. the when running QGIS under gnome. It results in incorrectly deciding that a widget belongs to an inactive window, causing unfocused list/tree or dock widgets to incorrectly show in the inactive color palette. On gnome at least this "inactive" palette defaults to an appearance very similar to the disabled widget color palette. As a result all unfocused list/tree/dock widgets look to be disabled until they are focused. This gross hack just force removes the inactive color palette under linux environments to block this theme behaviour (cherry picked from commit bad818a)
1 parent 53c91e7 commit ee096b1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
 

‎src/gui/qgsproxystyle.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QStyle>
2020
#include <QStyleOption>
2121
#include <QApplication>
22+
#include <QWindow>
2223

2324
QgsProxyStyle::QgsProxyStyle( QWidget *parent )
2425
: QProxyStyle( nullptr ) // no base style yet - it transfers ownership, so we need a NEW QStyle object for the base style
@@ -85,6 +86,27 @@ QPixmap QgsAppStyle::generatedIconPixmap( QIcon::Mode iconMode, const QPixmap &p
8586
return QProxyStyle::generatedIconPixmap( iconMode, pixmap, opt );
8687
}
8788

89+
void QgsAppStyle::polish( QWidget *widget )
90+
{
91+
QProxyStyle::polish( widget );
92+
93+
#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID)
94+
// fix broken inactive window coloring applying to unfocused docks or list/tree widgets
95+
// see eg https://github.com/FedoraQt/adwaita-qt/issues/126
96+
// the detection used by themes to determine if a widget belongs to an activated window is fragile, which
97+
// results in unfocused list/tree views or widget children being shown in the "deactivated window" palette coloring.
98+
// Gnome (adwaita) defaults to a coloring which makes widgets looks disabled in this inactive state.
99+
// So the best we can do here is force disable the inactive palette coloring to prevent this unwanted behavior.
100+
QPalette pal = widget->palette();
101+
pal.setColor( QPalette::Inactive, QPalette::Text, pal.color( QPalette::Active, QPalette::Text ) );
102+
pal.setColor( QPalette::Inactive, QPalette::Window, pal.color( QPalette::Active, QPalette::Window ) );
103+
pal.setColor( QPalette::Inactive, QPalette::WindowText, pal.color( QPalette::Active, QPalette::WindowText ) );
104+
pal.setColor( QPalette::Inactive, QPalette::Button, pal.color( QPalette::Active, QPalette::Button ) );
105+
pal.setColor( QPalette::Inactive, QPalette::ButtonText, pal.color( QPalette::Active, QPalette::ButtonText ) );
106+
widget->setPalette( pal );
107+
#endif
108+
}
109+
88110
QProxyStyle *QgsAppStyle::clone()
89111
{
90112
return new QgsAppStyle( mBaseStyle );

‎src/gui/qgsproxystyle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class GUI_EXPORT QgsAppStyle : public QProxyStyle
5656

5757
explicit QgsAppStyle( const QString &base );
5858
QPixmap generatedIconPixmap( QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt ) const override;
59+
void polish( QWidget *widget ) override;
5960

6061
QString baseStyle() const { return mBaseStyle; }
6162

0 commit comments

Comments
 (0)
Please sign in to comment.