Skip to content
Permalink
Browse files

[qt6] QDesktopWidget is gone

QScreen takes over.
We are randomly picking a top level widget to get the dpi as we have always been doing.
  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 25, 2021
1 parent 22695b5 commit ebb2c61cdc885878446f866de76699da7caa441f
Showing with 20 additions and 2 deletions.
  1. +8 −0 src/core/qgsapplication.cpp
  2. +12 −2 src/core/textrenderer/qgstextformat.cpp
@@ -81,7 +81,9 @@

#include "layout/qgspagesizeregistry.h"

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
#include <QDesktopWidget>
#endif
#include <QDir>
#include <QFile>
#include <QFileInfo>
@@ -99,6 +101,7 @@
#include <QStandardPaths>
#include <QRegularExpression>
#include <QTextStream>
#include <QScreen>

#ifndef Q_OS_WIN
#include <netinet/in.h>
@@ -1855,8 +1858,13 @@ 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 QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
if ( applyDevicePixelRatio && QApplication::desktop() )
scaledIconSize *= QApplication::desktop()->devicePixelRatio();
#else
if ( applyDevicePixelRatio && !QApplication::topLevelWidgets().isEmpty() )
scaledIconSize *= QApplication::topLevelWidgets().first()->screen()->devicePixelRatio();
#endif
return scaledIconSize;
}

@@ -23,8 +23,12 @@
#include "qgstextrendererutils.h"
#include "qgspallabeling.h"
#include <QFontDatabase>
#include <QDesktopWidget>
#include <QMimeData>
#include <QWidget>
#include <QScreen>
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
#include <QDesktopWidget>
#endif

QgsTextFormat::QgsTextFormat()
{
@@ -956,7 +960,13 @@ QPixmap QgsTextFormat::textFormatPreviewPixmap( const QgsTextFormat &format, QSi
newCoordXForm.setParameters( 1, 0, 0, 0, 0, 0 );
context.setMapToPixel( newCoordXForm );

context.setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
const double logicalDpiX = QgsApplication::desktop()->logicalDpiX();
#else
const double logicalDpiX = QApplication::topLevelWidgets().first()->screen()->devicePixelRatio();
#endif
context.setScaleFactor( logicalDpiX / 25.4 );

context.setUseAdvancedEffects( true );
context.setFlag( QgsRenderContext::Antialiasing, true );
context.setPainter( &painter );

0 comments on commit ebb2c61

Please sign in to comment.