Skip to content

Commit

Permalink
Fix a bunch of tiny icon sizes on hidpi displays
Browse files Browse the repository at this point in the history
(cherry picked from commit 773ee55)
  • Loading branch information
nyalldawson committed Jan 15, 2019
1 parent ee65a07 commit 7d88163
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/gui/editorwidgets/qgsmultiedittoolbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

#include "qgsmultiedittoolbutton.h"
#include "qgsapplication.h"
#include "qgsguiutils.h"

#include <QMenu>
QgsMultiEditToolButton::QgsMultiEditToolButton( QWidget *parent )
: QToolButton( parent )
{
setFocusPolicy( Qt::StrongFocus );

// set default tool button icon properties
setFixedSize( 22, 22 );
setStyleSheet( QStringLiteral( "QToolButton{ background: none; border: 1px solid rgba(0, 0, 0, 0%);} QToolButton:focus { border: 1px solid palette(highlight); }" ) );
setIconSize( QSize( 16, 16 ) );

int iconSize = QgsGuiUtils::scaleIconSize( 24 );
setIconSize( QSize( iconSize, iconSize ) );
// button width is 1.25 * icon size, height 1.1 * icon size. But we round to ensure even pixel sizes for equal margins
setFixedSize( 2 * static_cast< int >( 1.25 * iconSize / 2.0 ), 2 * static_cast< int >( iconSize * 1.1 / 2.0 ) );

setPopupMode( QToolButton::InstantPopup );

mMenu = new QMenu( this );
Expand Down
5 changes: 4 additions & 1 deletion src/gui/locator/qgslocatorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgsmapcanvas.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsguiutils.h"
#include <QLayout>
#include <QCompleter>
#include <QMenu>
Expand Down Expand Up @@ -75,7 +76,9 @@ QgsLocatorWidget::QgsLocatorWidget( QWidget *parent )
mProxyModel->setSourceModel( mLocatorModel );
mResultsView->setModel( mProxyModel );
mResultsView->setUniformRowHeights( true );
mResultsView->setIconSize( QSize( 16, 16 ) );

int iconSize = QgsGuiUtils::scaleIconSize( 16 );
mResultsView->setIconSize( QSize( iconSize, iconSize ) );
mResultsView->recalculateSize();

connect( mLocator, &QgsLocator::foundResult, this, &QgsLocatorWidget::addResult );
Expand Down
3 changes: 2 additions & 1 deletion src/gui/processing/qgsprocessingmodelerparameterwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "qgsprocessingguiregistry.h"
#include "models/qgsprocessingmodelalgorithm.h"
#include "qgsgui.h"
#include "qgsguiutils.h"
#include "qgsexpressioncontext.h"
#include <QHBoxLayout>
#include <QToolButton>
Expand All @@ -43,7 +44,7 @@ QgsProcessingModelerParameterWidget::QgsProcessingModelerParameterWidget( QgsPro
setFocusPolicy( Qt::StrongFocus );

// icon size is a bit bigger than text, but minimum size of 24 so that we get pixel-aligned rendering on low-dpi screens
int iconSize = static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.1, 24.0 ) ) );
int iconSize = QgsGuiUtils::scaleIconSize( 24 );

QHBoxLayout *hLayout = new QHBoxLayout();

Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgscompoundcolorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor &c
mAddCustomColorButton->setMinimumWidth( swatchAddSize );
mAddCustomColorButton->setMaximumWidth( swatchAddSize );

const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
mTabWidget->setIconSize( QSize( iconSize, iconSize ) );

if ( color.isValid() )
{
setColor( color );
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgsguiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ namespace QgsGuiUtils
QString key = QStringLiteral( "Windows/%1/geometry" ).arg( subKey );
return key;
}

int scaleIconSize( int standardSize )
{
QFontMetrics fm( ( QFont() ) );
const double scale = 1.1 * standardSize / 24;
return static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
}

}

//
Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsguiutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ namespace QgsGuiUtils
* \return A key name that can be used for the widget in settings.
*/
QString createWidgetKey( QWidget *widget, const QString &keyName = QString() );

/**
* 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
* displays.
*
* \a standardSize should be set to a standard icon size, e.g. 16, 24, 48, etc.
*
* \since QGIS 3.6
*/
int scaleIconSize( int standardSize );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgspropertyoverridebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgspanelwidget.h"
#include "qgspropertyassistantwidget.h"
#include "qgsauxiliarystorage.h"
#include "qgsguiutils.h"

#include <QClipboard>
#include <QMenu>
Expand All @@ -38,8 +39,7 @@ QgsPropertyOverrideButton::QgsPropertyOverrideButton( QWidget *parent,
{
setFocusPolicy( Qt::StrongFocus );

// icon size is a bit bigger than text, but minimum size of 24 so that we get pixel-aligned rendering on low-dpi screens
int iconSize = std::floor( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.1, 24.0 ) );
int iconSize = QgsGuiUtils::scaleIconSize( 24 );

// button width is 1.25 * icon size, height 1.1 * icon size. But we round to ensure even pixel sizes for equal margins
setFixedSize( 2 * static_cast< int >( 1.25 * iconSize / 2.0 ), 2 * static_cast< int >( iconSize * 1.1 / 2.0 ) );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgstextformatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ void QgsTextFormatWidget::initWidget()
connect( chkLineOrientationDependent, &QCheckBox::toggled, this, &QgsTextFormatWidget::chkLineOrientationDependent_toggled );
connect( mToolButtonConfigureSubstitutes, &QToolButton::clicked, this, &QgsTextFormatWidget::mToolButtonConfigureSubstitutes_clicked );

const int iconSize = QgsGuiUtils::scaleIconSize( 20 );
mOptionsTab->setIconSize( QSize( iconSize, iconSize ) );

mPreviewScaleComboBox->setMapCanvas( mMapCanvas );
mPreviewScaleComboBox->setShowCurrentScaleButton( true );
connect( mPreviewScaleComboBox, &QgsScaleWidget::scaleChanged, this, &QgsTextFormatWidget::previewScaleChanged );
Expand Down
4 changes: 3 additions & 1 deletion src/gui/symbology/qgsbrushstylecombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/

#include "qgsbrushstylecombobox.h"
#include "qgsguiutils.h"

#include <QList>
#include <QPair>
Expand Down Expand Up @@ -42,7 +43,8 @@ QgsBrushStyleComboBox::QgsBrushStyleComboBox( QWidget *parent )
<< qMakePair( Qt::Dense6Pattern, tr( "Dense 6" ) )
<< qMakePair( Qt::Dense7Pattern, tr( "Dense 7" ) );

setIconSize( QSize( 32, 16 ) );
int iconSize = QgsGuiUtils::scaleIconSize( 16 );
setIconSize( QSize( iconSize * 2, iconSize ) );

for ( int i = 0; i < styles.count(); i++ )
{
Expand Down
4 changes: 3 additions & 1 deletion src/gui/symbology/qgspenstylecombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "qgspenstylecombobox.h"

#include "qgsapplication.h"
#include "qgsguiutils.h"

#include <QList>
#include <QPair>
Expand All @@ -34,7 +35,8 @@ QgsPenStyleComboBox::QgsPenStyleComboBox( QWidget *parent )
<< qMakePair( Qt::DashDotLine, tr( "Dash Dot Line" ) )
<< qMakePair( Qt::DashDotDotLine, tr( "Dash Dot Dot Line" ) );

setIconSize( QSize( 32, 12 ) );
int iconSize = QgsGuiUtils::scaleIconSize( 16 );
setIconSize( QSize( iconSize * 2, iconSize ) );

for ( int i = 0; i < styles.count(); i++ )
{
Expand Down

0 comments on commit 7d88163

Please sign in to comment.