Skip to content

Commit 11dd417

Browse files
committed
Try to balance UI element sizes on windows builds
1 parent a48c146 commit 11dd417

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

python/core/qgis.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ Default threshold between map coordinates and device coordinates for map2pixel s
108108
Default Z coordinate value for 2.5d geometry
109109
This value have to be assigned to the Z coordinate for the new 2.5d geometry vertex.
110110
.. versionadded:: 3.0
111+
%End
112+
113+
static const double UI_SCALE_FACTOR;
114+
%Docstring
115+
UI scaling factor. This should be applied to all widget sizes obtained from font metrics,
116+
to account for differences in the default font sizes across different platforms.
117+
.. versionadded:: 3.0
111118
%End
112119

113120
};

src/core/qgis.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ const double Qgis::SCALE_PRECISION = 0.9999999999;
8484

8585
const double Qgis::DEFAULT_Z_COORDINATE = 0.0;
8686

87+
#ifdef Q_OS_WIN
88+
const double Qgis::UI_SCALE_FACTOR = 1.5;
89+
#else
90+
const double Qgis::UI_SCALE_FACTOR = 1;
91+
#endif
92+
8793
double qgsPermissiveToDouble( QString string, bool &ok )
8894
{
8995
//remove any thousands separators

src/core/qgis.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ class CORE_EXPORT Qgis
120120
* \since QGIS 3.0 */
121121
static const double DEFAULT_Z_COORDINATE;
122122

123+
/**
124+
* UI scaling factor. This should be applied to all widget sizes obtained from font metrics,
125+
* to account for differences in the default font sizes across different platforms.
126+
* \since QGIS 3.0
127+
*/
128+
static const double UI_SCALE_FACTOR;
129+
123130
};
124131

125132
// hack to workaround warnings when casting void pointers

src/gui/qgscolorswatchgrid.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ QgsColorSwatchGrid::QgsColorSwatchGrid( QgsColorScheme *scheme, const QString &c
3838
setFocusPolicy( Qt::StrongFocus );
3939
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
4040

41-
mLabelHeight = fontMetrics().height();
42-
mLabelMargin = fontMetrics().width( QStringLiteral( "." ) );
41+
mLabelHeight = Qgis::UI_SCALE_FACTOR * fontMetrics().height();
42+
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "." ) );
4343

44-
mSwatchSize = fontMetrics().width( QStringLiteral( "X" ) ) * 1.75;
45-
mSwatchOutlineSize = qMax( mLabelMargin * 0.4, 1.0 );
44+
mSwatchSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "X" ) ) * 1.75;
45+
mSwatchOutlineSize = qMax( fontMetrics().width( QStringLiteral( "." ) ) * 0.4, 1.0 );
4646

4747
mSwatchSpacing = mSwatchSize * 0.3;
48-
mSwatchMargin = mLabelMargin * 1.5;
48+
mSwatchMargin = mLabelMargin;
4949

5050
//calculate widget width
5151
mWidth = NUMBER_COLORS_PER_ROW * mSwatchSize + ( NUMBER_COLORS_PER_ROW - 1 ) * mSwatchSpacing + mSwatchMargin + mSwatchMargin;

src/gui/qgscolorwidgets.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ QgsColorWheel::~QgsColorWheel()
397397

398398
QSize QgsColorWheel::sizeHint() const
399399
{
400-
int size = fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
400+
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
401401
return QSize( size, size );
402402
}
403403

@@ -758,7 +758,7 @@ QgsColorBox::~QgsColorBox()
758758

759759
QSize QgsColorBox::sizeHint() const
760760
{
761-
int size = fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
761+
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
762762
return QSize( size, size );
763763
}
764764

@@ -991,12 +991,12 @@ QSize QgsColorRampWidget::sizeHint() const
991991
if ( mOrientation == QgsColorRampWidget::Horizontal )
992992
{
993993
//horizontal
994-
return QSize( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), fontMetrics().height() * 1.3 );
994+
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3 );
995995
}
996996
else
997997
{
998998
//vertical
999-
return QSize( fontMetrics().height() * 1.3, fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) );
999+
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) );
10001000
}
10011001
}
10021002

@@ -1598,7 +1598,7 @@ void QgsColorPreviewWidget::paintEvent( QPaintEvent *event )
15981598

15991599
QSize QgsColorPreviewWidget::sizeHint() const
16001600
{
1601-
return QSize( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) * 0.75 );
1601+
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) * 0.75 );
16021602
}
16031603

16041604
void QgsColorPreviewWidget::setColor2( const QColor &color )

src/gui/qgsmenuheader.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ QgsMenuHeader::QgsMenuHeader( const QString &text, QWidget *parent )
2525
{
2626
int textMinWidth = fontMetrics().width( mText );
2727
mTextHeight = fontMetrics().height();
28-
mLabelMargin = fontMetrics().width( QStringLiteral( "." ) );
28+
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "." ) );
2929
mMinWidth = 2 * mLabelMargin + textMinWidth;
3030
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
3131
updateGeometry();
3232
}
3333

3434
QSize QgsMenuHeader::minimumSizeHint() const
3535
{
36-
return QSize( mMinWidth, mTextHeight + 0.5 * mLabelMargin );
36+
return QSize( mMinWidth, mTextHeight + mLabelMargin );
3737
}
3838

3939
QSize QgsMenuHeader::sizeHint() const
4040
{
41-
return QSize( mMinWidth, mTextHeight + 0.5 * mLabelMargin );
41+
return QSize( mMinWidth, mTextHeight + mLabelMargin );
4242
}
4343

4444
void QgsMenuHeader::paintEvent( QPaintEvent * )
@@ -51,12 +51,11 @@ void QgsMenuHeader::paintEvent( QPaintEvent * )
5151
//draw header background
5252
painter.setBrush( headerBgColor );
5353
painter.setPen( Qt::NoPen );
54-
painter.drawRect( QRect( 0, 0, width(), mTextHeight + 0.5 * mLabelMargin ) );
54+
painter.drawRect( QRect( 0, 0, width(), mTextHeight + mLabelMargin ) );
5555

5656
//draw header text
5757
painter.setPen( headerTextColor );
58-
painter.drawText( QRect( mLabelMargin, 0.25 * mLabelMargin, width() - 2 * mLabelMargin, mTextHeight ),
59-
Qt::AlignLeft | Qt::AlignVCenter, mText );
58+
painter.drawText( QPoint( mLabelMargin, 0.25 * mLabelMargin + mTextHeight ), mText );
6059
painter.end();
6160
}
6261

0 commit comments

Comments
 (0)