Skip to content
Permalink
Browse files

On first run, try to guess a good default icon size based on screen DPI

Otherwise icons are miniscule when loading QGIS on hidpi screens, and
users must know that they need to manually change the icon size
to make it usable...
  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent dbd50b4 commit 71b9ce25c630a30d3b20b4d2099db1e64573b647
Showing with 43 additions and 2 deletions.
  1. +40 −2 src/app/qgisapp.cpp
  2. +3 −0 src/app/qgisapp.h
@@ -50,6 +50,7 @@
#include <QProgressDialog>
#include <QRegExp>
#include <QRegExpValidator>
#include <QScreen>
#include <QShortcut>
#include <QSpinBox>
#include <QSplashScreen>
@@ -1033,8 +1034,20 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}

// Set icon size of toolbars
int size = settings.value( QStringLiteral( "IconSize" ), QGIS_ICON_SIZE ).toInt();
setIconSizes( size );
if ( settings.contains( QStringLiteral( "IconSize" ) ) )
{
int size = settings.value( QStringLiteral( "IconSize" ) ).toInt();
if ( size < 16 )
size = QGIS_ICON_SIZE;
setIconSizes( size );
}
else
{
// first run, guess a good icon size
int size = chooseReasonableDefaultIconSize();
settings.setValue( QStringLiteral( "IconSize" ), size );
setIconSizes( size );
}

mSplash->showMessage( tr( "Initializing file filters" ), Qt::AlignHCenter | Qt::AlignBottom );
qApp->processEvents();
@@ -1729,6 +1742,31 @@ QgsCoordinateReferenceSystem QgisApp::defaultCrsForNewLayers() const
return defaultCrs;
}

int QgisApp::chooseReasonableDefaultIconSize() const
{
QScreen *screen = QApplication::screens().at( 0 );
if ( screen->physicalDotsPerInch() < 115 )
{
// no hidpi screen, use default size
return QGIS_ICON_SIZE;
}
else
{
double size = fontMetrics().width( QStringLiteral( "XXX" ) );
if ( size < 24 )
return 16;
else if ( size < 32 )
return 24;
else if ( size < 48 )
return 32;
else if ( size < 64 )
return 48;
else
return 64;
}

}

void QgisApp::readSettings()
{
QgsSettings settings;
@@ -1688,6 +1688,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;

//! Attempts to choose a reasonable default icon size based on the window's screen DPI
int chooseReasonableDefaultIconSize() const;

QgisAppStyleSheet *mStyleSheetBuilder = nullptr;

// actions for menus and toolbars -----------------

2 comments on commit 71b9ce2

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Jul 18, 2017

Nice idea to set the icon size based on fontMetrics.
Do you know if that takes system default font sizes into account? If yes, wouldn't it make sense to always use this logic (also for low res displays) so people with visual impairment and increased font size also get bigger icons by default?

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Jul 18, 2017

Sounds reasonable to me. Let me test on some low res displays tomorrow and confirm.

Please sign in to comment.
You can’t perform that action at this time.