Skip to content
Permalink
Browse files
Merge pull request #42733 from nyalldawson/no_top_level_widgets
Use QApplication::activeWindow() instead of QApplication::topLevelWidgets() to retrieve current screen
  • Loading branch information
m-kuhn committed Apr 9, 2021
2 parents 3ee49a6 + 881078f commit 6fa5a1eeaeb5843f16b1306f9e109c5b0ad2cf34
Showing with 9 additions and 4 deletions.
  1. +2 −1 src/core/labeling/qgspallabeling.cpp
  2. +5 −2 src/core/qgsapplication.cpp
  3. +2 −1 src/core/textrenderer/qgstextformat.cpp
@@ -1312,7 +1312,8 @@ QPixmap QgsPalLayerSettings::labelSettingsPreviewPixmap( const QgsPalLayerSettin
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
const double logicalDpiX = QgsApplication::desktop()->logicalDpiX();
#else
const double logicalDpiX = QApplication::topLevelWidgets().first()->screen()->logicalDotsPerInchX();
QWidget *activeWindow = QApplication::activeWindow();
const double logicalDpiX = activeWindow && activeWindow->screen() ? activeWindow->screen()->logicalDotsPerInchX() : 96.0;
#endif
context.setScaleFactor( logicalDpiX / 25.4 );

@@ -1865,8 +1865,11 @@ int QgsApplication::scaleIconSize( int standardSize, bool applyDevicePixelRatio
if ( applyDevicePixelRatio && QApplication::desktop() )
scaledIconSize *= QApplication::desktop()->devicePixelRatio();
#else
if ( applyDevicePixelRatio && !QApplication::topLevelWidgets().isEmpty() )
scaledIconSize *= QApplication::topLevelWidgets().first()->screen()->devicePixelRatio();
if ( applyDevicePixelRatio )
{
if ( QWidget *activeWindow = QApplication::activeWindow() )
scaledIconSize *= ( activeWindow->screen() ? QApplication::activeWindow()->screen()->devicePixelRatio() : 1 );
}
#endif
return scaledIconSize;
}
@@ -963,7 +963,8 @@ QPixmap QgsTextFormat::textFormatPreviewPixmap( const QgsTextFormat &format, QSi
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
const double logicalDpiX = QgsApplication::desktop()->logicalDpiX();
#else
const double logicalDpiX = QApplication::topLevelWidgets().first()->screen()->logicalDotsPerInchX();
QWidget *activeWindow = QApplication::activeWindow();
const double logicalDpiX = activeWindow && activeWindow->screen() ? activeWindow->screen()->logicalDotsPerInchX() : 96.0;
#endif
context.setScaleFactor( logicalDpiX / 25.4 );

0 comments on commit 6fa5a1e

Please sign in to comment.