Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use Qt formal API for setting application font instead of stylesheet
This should hopefully help address some hi-dpi font scaling issues
  • Loading branch information
nyalldawson committed May 17, 2023
1 parent 33ea58d commit 39e6f75
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/app/qgisappstylesheet.cpp
Expand Up @@ -58,13 +58,14 @@ void QgisAppStyleSheet::applyStyleSheet( const QMap<QString, QVariant> &opts )
{
bool overriddenFontSize = false;
double currentFontSize = fontSize();
const QFont appFont = QApplication::font();
if ( opts.contains( QStringLiteral( "fontPointSize" ) ) )
{
const double fontSizeFromOpts = opts.value( QStringLiteral( "fontPointSize" ) ).toDouble();
currentFontSize = fontSizeFromOpts;
}
QgsDebugMsgLevel( QStringLiteral( "fontPointSize: %1" ).arg( currentFontSize ), 2 );
if ( currentFontSize != defaultFont().pointSizeF() )
if ( currentFontSize != appFont.pointSizeF() )
{
overriddenFontSize = true;
}
Expand All @@ -76,17 +77,20 @@ void QgisAppStyleSheet::applyStyleSheet( const QMap<QString, QVariant> &opts )
currentFontFamily = opts.value( QStringLiteral( "fontFamily" ) ).toString();
}
QgsDebugMsgLevel( QStringLiteral( "fontFamily: %1" ).arg( currentFontFamily ), 2 );
if ( !currentFontFamily.isEmpty() && currentFontFamily != defaultFont().family() )
if ( !currentFontFamily.isEmpty() && currentFontFamily != appFont.family() )
{
overriddenFontFamily = true;
}

if ( overriddenFontFamily && overriddenFontSize )
ss += QStringLiteral( "* { font: %1pt \"%2\"} " ).arg( currentFontSize ).arg( currentFontFamily );
else if ( overriddenFontFamily )
ss += QStringLiteral( "* { font-family: \"%1\"} " ).arg( currentFontFamily );
else if ( overriddenFontSize )
ss += QStringLiteral( "* { font-size: %1pt } " ).arg( currentFontSize );
if ( overriddenFontFamily || overriddenFontSize )
{
QFont font = QApplication::font();
if ( overriddenFontFamily )
font.setFamily( currentFontFamily );
if ( overriddenFontSize )
font.setPointSizeF( currentFontSize );
QApplication::setFont( font );
}
}

if ( mMacStyle )
Expand Down

0 comments on commit 39e6f75

Please sign in to comment.