Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI scale factor setting for high DPI screens #1763

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QStyleFactory>
#include <QFontDatabase>
#include <QSysInfo>
#include <QSettings>
#ifdef __APPLE__
#include <QGLFormat>
#include <QSurfaceFormat>
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions sdrgui/gui/graphicsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
///////////////////////////////////////////////////////////////////////////////////

#include <QFileDialog>
#include <QSettings>
#include <QMessageBox>

#include "graphicsdialog.h"
#include "ui_graphicsdialog.h"
Expand All @@ -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()
Expand All @@ -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));
}
2 changes: 2 additions & 0 deletions sdrgui/gui/graphicsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
46 changes: 44 additions & 2 deletions sdrgui/gui/graphicsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>282</width>
<height>155</height>
<height>218</height>
</rect>
</property>
<property name="font">
Expand All @@ -20,6 +20,45 @@
<string>Graphics settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>UI</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QLabel" name="uiScaleFactorText">
<property name="text">
<string>100.0%</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="uiScaleFactorLabel">
<property name="text">
<string>UI Scale Factor</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="uiScaleFactor">
<property name="toolTip">
<string>UI scale factor. Set &gt;100% for high DPI displays. Requires restarting SDRangel to apply</string>
</property>
<property name="minimum">
<number>100</number>
</property>
<property name="maximum">
<number>300</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
Expand Down Expand Up @@ -165,7 +204,10 @@ Requires windows to be reopened to take effect</string>
</layout>
</widget>
<tabstops>
<tabstop>buttonBox</tabstop>
<tabstop>uiScaleFactor</tabstop>
<tabstop>multisampling</tabstop>
<tabstop>mapMultisampling</tabstop>
<tabstop>mapSmoothing</tabstop>
</tabstops>
<resources>
<include location="../resources/res.qrc"/>
Expand Down