Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
43 additions
and
2 deletions .
+40
−2
src/app/qgisapp.cpp
+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 -----------------
Toggle all file notes
This comment has been minimized.
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?
This comment has been minimized.
Sounds reasonable to me. Let me test on some low res displays tomorrow and confirm.