Skip to content

Commit

Permalink
[qt6] QDesktopWidget is gone
Browse files Browse the repository at this point in the history
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 ebb2c61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -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>
Expand All @@ -99,6 +101,7 @@
#include <QStandardPaths>
#include <QRegularExpression>
#include <QTextStream>
#include <QScreen>

#ifndef Q_OS_WIN
#include <netinet/in.h>
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 12 additions & 2 deletions src/core/textrenderer/qgstextformat.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit ebb2c61

Please sign in to comment.