From f934042a98fe8210207ffc62ddd9b1471d3d72ef Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 9 May 2018 15:46:17 +0800 Subject: [PATCH] Fix GUI scaling factor on macOS macOS seems have an unique way to handle widget size, that is, it doesn't require application to resize widgets manually, Qt will handle the resize job automatically. Closes #8841. --- src/gui/utils.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index 5709810b2..4b83e3fda 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -45,16 +45,21 @@ void Utils::Gui::resize(QWidget *widget, const QSize &newSize) qreal Utils::Gui::screenScalingFactor(const QWidget *widget) { + if (!widget) + return 1; + #ifdef Q_OS_WIN const int screen = qApp->desktop()->screenNumber(widget); return (QApplication::screens()[screen]->logicalDotsPerInch() / 96); +#elif defined(Q_OS_MAC) + return 1; #else #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) return widget->devicePixelRatioF(); #else return widget->devicePixelRatio(); #endif -#endif // Q_OS_WIN +#endif } QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, const int height)