Skip to content

Commit

Permalink
Only apply device pixel ratio in scaleIconSize for tested use
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Oct 16, 2020
1 parent 746ee31 commit c606cf8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsapplication.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ Set a single custom expression variable.
.. versionadded:: 3.0
%End

static int scaleIconSize( int standardSize );
static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );
%Docstring
Scales an icon size to compensate for display pixel density, making the icon
size hi-dpi friendly, whilst still resulting in pixel-perfect sizes for low-dpi
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ void QgsLayerTreeModel::setLayerStyleOverrides( const QMap<QString, QString> &ov

int QgsLayerTreeModel::scaleIconSize( int standardSize )
{
return QgsApplication::scaleIconSize( standardSize );
return QgsApplication::scaleIconSize( standardSize, true );
}

void QgsLayerTreeModel::nodeWillAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo )
Expand Down
5 changes: 2 additions & 3 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@

#include "layout/qgspagesizeregistry.h"

#include <QApplication>
#include <QDesktopWidget>
#include <QDir>
#include <QFile>
Expand Down Expand Up @@ -1822,12 +1821,12 @@ void QgsApplication::setCustomVariable( const QString &name, const QVariant &val
emit instance()->customVariablesChanged();
}

int QgsApplication::scaleIconSize( int standardSize )
int QgsApplication::scaleIconSize( int standardSize, bool applyDevicePixelRatio )
{
QFontMetrics fm( ( QFont() ) );
const double scale = 1.1 * standardSize / 24;
int scaledIconSize = static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
if ( QApplication::desktop() )
if ( applyDevicePixelRatio && QApplication::desktop() )
scaledIconSize *= QApplication::desktop()->devicePixelRatio();
return scaledIconSize;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ class CORE_EXPORT QgsApplication : public QApplication
*
* \since QGIS 3.16
*/
static int scaleIconSize( int standardSize );
static int scaleIconSize( int standardSize, bool applyDevicePixelRatio = false );

/**
* The maximum number of concurrent connections per connections pool.
Expand Down

0 comments on commit c606cf8

Please sign in to comment.