Skip to content

Commit

Permalink
Workaround broken inactive window coloring applies incorrectly
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
nyalldawson committed Jan 24, 2022
1 parent 53c91e7 commit ee096b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/gui/qgsproxystyle.cpp
Expand Up @@ -19,6 +19,7 @@
#include <QStyle>
#include <QStyleOption>
#include <QApplication>
#include <QWindow>

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

void QgsAppStyle::polish( QWidget *widget )
{
QProxyStyle::polish( widget );

#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID)
// fix broken inactive window coloring applying to unfocused docks or list/tree widgets
// see eg https://github.com/FedoraQt/adwaita-qt/issues/126
// the detection used by themes to determine if a widget belongs to an activated window is fragile, which
// results in unfocused list/tree views or widget children being shown in the "deactivated window" palette coloring.
// Gnome (adwaita) defaults to a coloring which makes widgets looks disabled in this inactive state.
// So the best we can do here is force disable the inactive palette coloring to prevent this unwanted behavior.
QPalette pal = widget->palette();
pal.setColor( QPalette::Inactive, QPalette::Text, pal.color( QPalette::Active, QPalette::Text ) );
pal.setColor( QPalette::Inactive, QPalette::Window, pal.color( QPalette::Active, QPalette::Window ) );
pal.setColor( QPalette::Inactive, QPalette::WindowText, pal.color( QPalette::Active, QPalette::WindowText ) );
pal.setColor( QPalette::Inactive, QPalette::Button, pal.color( QPalette::Active, QPalette::Button ) );
pal.setColor( QPalette::Inactive, QPalette::ButtonText, pal.color( QPalette::Active, QPalette::ButtonText ) );
widget->setPalette( pal );
#endif
}

QProxyStyle *QgsAppStyle::clone()
{
return new QgsAppStyle( mBaseStyle );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsproxystyle.h
Expand Up @@ -56,6 +56,7 @@ class GUI_EXPORT QgsAppStyle : public QProxyStyle

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

QString baseStyle() const { return mBaseStyle; }

Expand Down

0 comments on commit ee096b1

Please sign in to comment.