Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enforce use of qt's fusion style for non-default themes
  • Loading branch information
nirvn committed Dec 28, 2018
1 parent b84c097 commit 0f8e291
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
17 changes: 15 additions & 2 deletions src/app/main.cpp
Expand Up @@ -1222,6 +1222,16 @@ int main( int argc, char *argv[] )
// Set the application style. If it's not set QT will use the platform style except on Windows
// as it looks really ugly so we use QPlastiqueStyle.
QString presetStyle = settings.value( QStringLiteral( "qgis/style" ) ).toString();
#ifndef Q_OS_MACX
QString theme = settings.value( QStringLiteral( "UI/UITheme" ) ).toString();
if ( theme != QStringLiteral( "default" ) )
{
if ( QStyleFactory::keys().contains( QStringLiteral( "fusion" ), Qt::CaseInsensitive ) )
{
presetStyle = QStringLiteral( "fusion" );
}
}
#endif
QString activeStyleName = presetStyle;
if ( activeStyleName.isEmpty() ) // not set, using default style
{
Expand All @@ -1238,13 +1248,16 @@ int main( int argc, char *argv[] )
//style choices can cause Qt apps to crash...
if ( QStyleFactory::keys().contains( QStringLiteral( "fusion" ), Qt::CaseInsensitive ) )
{
presetStyle = QStringLiteral( "fusion" );
activeStyleName = QStringLiteral( "fusion" );
}
}
if ( activeStyleName != presetStyle )
{
settings.setValue( QStringLiteral( "qgis/style" ), QApplication::style()->objectName() );
}
if ( !presetStyle.isEmpty() )
{
QApplication::setStyle( presetStyle );
settings.setValue( QStringLiteral( "qgis/style" ), QApplication::style()->objectName() );
}

// set authentication database directory
Expand Down
9 changes: 3 additions & 6 deletions src/app/qgsoptions.cpp
Expand Up @@ -135,7 +135,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
}
if ( filteredStyles.isEmpty() )
{
//oops - none left!.. have to let user use a broken style
// oops - none left!.. have to let user use a broken style
filteredStyles = styles;
}

Expand All @@ -144,11 +144,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
QStringList themes = QgsApplication::uiThemes().keys();
cmbUITheme->addItems( themes );

#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
// non-default themes are best rendered using the Fusion style, therefore changing themes must require a restart to
lblUITheme->setText( QStringLiteral( "%1 <i>(%2)</i>" ).arg( lblUITheme->text(), tr( "QGIS restart required" ) ) );
#else
connect( cmbUITheme, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsOptions::uiThemeChanged );
#endif

mIdentifyHighlightColorButton->setColorDialogTitle( tr( "Identify Highlight Color" ) );
mIdentifyHighlightColorButton->setAllowOpacity( true );
Expand Down Expand Up @@ -566,7 +563,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
QString name = mSettings->value( QStringLiteral( "/qgis/style" ) ).toString();
whileBlocking( cmbStyle )->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) );

QString theme = mSettings->value( QStringLiteral( "UI/UITheme" ), QStringLiteral( "auto" ) ).toString();
QString theme = mSettings->value( QStringLiteral( "UI/UITheme" ), QStringLiteral( "default" ) ).toString();
whileBlocking( cmbUITheme )->setCurrentIndex( cmbUITheme->findText( theme, Qt::MatchFixedString ) );

mNativeColorDialogsChkBx->setChecked( mSettings->value( QStringLiteral( "/qgis/native_color_dialogs" ), false ).toBool() );
Expand Down

0 comments on commit 0f8e291

Please sign in to comment.