Skip to content

Commit 5068024

Browse files
authored
Merge pull request #4397 from nyalldawson/no_adawaita
Block use of the Adwaita themes if we can avoid them
2 parents 9e662a7 + 98e25d1 commit 5068024

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/app/main.cpp

+23-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QString>
3030
#include <QStringList>
3131
#include <QStyle>
32+
#include <QStyleFactory>
3233
#include <QDesktopWidget>
3334
#include <QTranslator>
3435
#include <QImageReader>
@@ -957,13 +958,31 @@ int main( int argc, char *argv[] )
957958

958959
// Set the application style. If it's not set QT will use the platform style except on Windows
959960
// as it looks really ugly so we use QPlastiqueStyle.
960-
QString style = mySettings.value( QStringLiteral( "qgis/style" ) ).toString();
961-
if ( !style.isNull() )
961+
QString presetStyle = mySettings.value( QStringLiteral( "qgis/style" ) ).toString();
962+
QString activeStyleName = presetStyle;
963+
if ( activeStyleName.isEmpty() ) // not set, using default style
962964
{
963-
QApplication::setStyle( style );
964-
mySettings.setValue( QStringLiteral( "qgis/style" ), QApplication::style()->objectName() );
965+
//not set, check default
966+
activeStyleName = QApplication::style()->metaObject()->className() ;
965967
}
968+
if ( activeStyleName.contains( QStringLiteral( "adwaita" ), Qt::CaseInsensitive ) )
969+
{
970+
//never allow Adwaita themes - the Qt variants of these are VERY broken
971+
//for apps like QGIS. E.g. oversized controls like spinbox widgets prevent actually showing
972+
//any content in these widgets, leaving a very bad impression of QGIS
966973

974+
//note... we only do this if there's a known good style available (fusion), as SOME
975+
//style choices can cause Qt apps to crash...
976+
if ( QStyleFactory::keys().contains( QStringLiteral( "fusion" ), Qt::CaseInsensitive ) )
977+
{
978+
presetStyle = QStringLiteral( "fusion" );
979+
}
980+
}
981+
if ( !presetStyle.isEmpty() )
982+
{
983+
QApplication::setStyle( presetStyle );
984+
mySettings.setValue( QStringLiteral( "qgis/style" ), QApplication::style()->objectName() );
985+
}
967986
/* Translation file for QGIS.
968987
*/
969988
QString i18nPath = QgsApplication::i18nPath();

src/app/qgsoptions.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,22 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
101101
connect( this, &QDialog::rejected, this, &QgsOptions::rejectOptions );
102102

103103
QStringList styles = QStyleFactory::keys();
104-
cmbStyle->addItems( styles );
104+
QStringList filteredStyles = styles;
105+
for ( int i = filteredStyles.count() - 1; i >= 0; --i )
106+
{
107+
// filter out the broken adwaita styles - see note in main.cpp
108+
if ( filteredStyles.at( i ).contains( QStringLiteral( "adwaita" ), Qt::CaseInsensitive ) )
109+
{
110+
filteredStyles.removeAt( i );
111+
}
112+
}
113+
if ( filteredStyles.isEmpty() )
114+
{
115+
//oops - none left!.. have to let user use a broken style
116+
filteredStyles = styles;
117+
}
118+
119+
cmbStyle->addItems( filteredStyles );
105120

106121
QStringList themes = QgsApplication::uiThemes().keys();
107122
cmbUITheme->addItems( themes );

0 commit comments

Comments
 (0)