From d0d07194f8e0e4cb177dce4db3b4660c92f22e1d Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Sun, 6 Aug 2023 12:26:17 +0100 Subject: [PATCH] Add UI scale factor setting for high DPI screens --- app/main.cpp | 11 +++++++++ sdrgui/gui/graphicsdialog.cpp | 31 +++++++++++++++++++++++ sdrgui/gui/graphicsdialog.h | 2 ++ sdrgui/gui/graphicsdialog.ui | 46 +++++++++++++++++++++++++++++++++-- 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index 5c433ea3c2..4cda1ffa3a 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef __APPLE__ #include #include @@ -56,6 +57,16 @@ static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *lo QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); // Don't use on Android, otherwise we can't access files on internal storage #endif + // Set UI scale factor for High DPI displays + QSettings settings; + QString uiScaleFactor = "graphics.ui_scale_factor"; + if (settings.contains(uiScaleFactor)) + { + QString scaleFactor = settings.value(uiScaleFactor).toString(); + qDebug() << "Setting QT_SCALE_FACTOR to" << scaleFactor; + qputenv("QT_SCALE_FACTOR", scaleFactor.toLatin1()); + } + QApplication a(argc, argv); #if 1 diff --git a/sdrgui/gui/graphicsdialog.cpp b/sdrgui/gui/graphicsdialog.cpp index cc81c5962c..e8dc343729 100644 --- a/sdrgui/gui/graphicsdialog.cpp +++ b/sdrgui/gui/graphicsdialog.cpp @@ -16,6 +16,8 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include +#include #include "graphicsdialog.h" #include "ui_graphicsdialog.h" @@ -39,6 +41,10 @@ GraphicsDialog::GraphicsDialog(MainSettings& mainSettings, QWidget* parent) : ui->mapMultisampling->setCurrentText(QString::number(samples)); } ui->mapSmoothing->setChecked(m_mainSettings.getMapSmoothing()); + + QSettings settings; + m_initScaleFactor = settings.value("graphics.ui_scale_factor", "1").toFloat(); + ui->uiScaleFactor->setValue((int)(m_initScaleFactor * 100.0f)); } GraphicsDialog::~GraphicsDialog() @@ -51,5 +57,30 @@ void GraphicsDialog::accept() m_mainSettings.setMultisampling(ui->multisampling->currentText().toInt()); m_mainSettings.setMapMultisampling(ui->mapMultisampling->currentText().toInt()); m_mainSettings.setMapSmoothing(ui->mapSmoothing->isChecked()); + + // We use QSetting rather than MainSettings, as we need to set QT_SCALE_FACTOR + // before MainSettings are currently read + QSettings settings; + bool showRestart = false; + + float scaleFactor = ui->uiScaleFactor->value() / 100.0f; + if (m_initScaleFactor != scaleFactor) + { + QString newScaleFactor = QString("%1").arg(scaleFactor); + settings.setValue("graphics.ui_scale_factor", newScaleFactor); + showRestart = true; + } + + if (showRestart) + { + QMessageBox msgBox; + msgBox.setText("Please restart SDRangel to use the new UI settings."); + msgBox.exec(); + } QDialog::accept(); } + +void GraphicsDialog::on_uiScaleFactor_valueChanged(int value) +{ + ui->uiScaleFactorText->setText(QString("%1%").arg(value)); +} diff --git a/sdrgui/gui/graphicsdialog.h b/sdrgui/gui/graphicsdialog.h index ffba3e4f67..ec5eefca69 100644 --- a/sdrgui/gui/graphicsdialog.h +++ b/sdrgui/gui/graphicsdialog.h @@ -35,9 +35,11 @@ class SDRGUI_API GraphicsDialog : public QDialog { private: Ui::GraphicsDialog* ui; MainSettings& m_mainSettings; + float m_initScaleFactor; private slots: void accept(); + void on_uiScaleFactor_valueChanged(int value); }; #endif /* SDRGUI_GUI_GRAPHICS_H_ */ diff --git a/sdrgui/gui/graphicsdialog.ui b/sdrgui/gui/graphicsdialog.ui index 761658d73c..3cd234d9ff 100644 --- a/sdrgui/gui/graphicsdialog.ui +++ b/sdrgui/gui/graphicsdialog.ui @@ -7,7 +7,7 @@ 0 0 282 - 155 + 218 @@ -20,6 +20,45 @@ Graphics settings + + + + UI + + + + + + 100.0% + + + + + + + UI Scale Factor + + + + + + + UI scale factor. Set >100% for high DPI displays. Requires restarting SDRangel to apply + + + 100 + + + 300 + + + Qt::Horizontal + + + + + + @@ -165,7 +204,10 @@ Requires windows to be reopened to take effect - buttonBox + uiScaleFactor + multisampling + mapMultisampling + mapSmoothing