mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-21 23:55:13 -05:00
Add UI scale factor setting for high DPI screens
This commit is contained in:
parent
958078c37b
commit
d0d07194f8
11
app/main.cpp
11
app/main.cpp
@ -22,6 +22,7 @@
|
||||
#include <QStyleFactory>
|
||||
#include <QFontDatabase>
|
||||
#include <QSysInfo>
|
||||
#include <QSettings>
|
||||
#ifdef __APPLE__
|
||||
#include <QGLFormat>
|
||||
#include <QSurfaceFormat>
|
||||
@ -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
|
||||
|
@ -16,6 +16,8 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QSettings>
|
||||
#include <QMessageBox>
|
||||
|
||||
#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));
|
||||
}
|
||||
|
@ -35,9 +35,11 @@ public:
|
||||
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_ */
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>282</width>
|
||||
<height>155</height>
|
||||
<height>218</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
@ -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 >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">
|
||||
@ -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"/>
|
||||
|
Loading…
Reference in New Issue
Block a user