Skip to content

Commit b43aa13

Browse files
Allow to use Qt's default QStyle
Relevant prior PR qbittorrent#21553
1 parent 25dbea1 commit b43aa13

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

src/gui/optionsdialog.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ void OptionsDialog::saveBehaviorTabOptions() const
461461
pref->setLocale(locale);
462462

463463
#ifdef Q_OS_WIN
464-
pref->setStyle(m_ui->comboStyle->currentText());
464+
if (const QVariant systemStyle = m_ui->comboStyle->currentData(); systemStyle.isValid())
465+
pref->setStyle(systemStyle.toString());
466+
else
467+
pref->setStyle(m_ui->comboStyle->currentText());
465468
#endif
466469

467470
#ifdef QBT_HAS_COLORSCHEME_OPTION
@@ -1698,18 +1701,27 @@ bool OptionsDialog::isSplashScreenDisabled() const
16981701
void OptionsDialog::initializeStyleCombo()
16991702
{
17001703
#ifdef Q_OS_WIN
1704+
m_ui->labelStyleHint->setText(tr("%1 is recommended for best compatibility with Windows dark mode"
1705+
, "Fusion is recommended for best compatibility with Windows dark mode").arg(u"Fusion"_s));
1706+
m_ui->comboStyle->addItem(tr("System", "System default Qt style"), u"system"_s);
1707+
m_ui->comboStyle->setItemData(0, tr("Let Qt decide the style for this system"), Qt::ToolTipRole);
1708+
m_ui->comboStyle->insertSeparator(1);
1709+
17011710
QStringList styleNames = QStyleFactory::keys();
17021711
std::sort(styleNames.begin(), styleNames.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
17031712
m_ui->comboStyle->addItems(styleNames);
17041713
const QString prefStyleName = Preferences::instance()->getStyle();
17051714
const QString selectedStyleName = prefStyleName.isEmpty() ? QApplication::style()->name() : prefStyleName;
1706-
m_ui->comboStyle->setCurrentText(selectedStyleName);
1715+
1716+
if (selectedStyleName.compare(u"system"_s, Qt::CaseInsensitive) != 0)
1717+
m_ui->comboStyle->setCurrentText(selectedStyleName);
17071718
#else
17081719
m_ui->labelStyle->hide();
17091720
m_ui->comboStyle->hide();
1721+
m_ui->labelStyleHint->hide();
17101722
m_ui->UISettingsBoxLayout->removeWidget(m_ui->labelStyle);
17111723
m_ui->UISettingsBoxLayout->removeWidget(m_ui->comboStyle);
1712-
m_ui->UISettingsBoxLayout->removeItem(m_ui->spacerStyle);
1724+
m_ui->UISettingsBoxLayout->removeWidget(m_ui->labelStyleHint);
17131725
#endif
17141726
}
17151727

src/gui/optionsdialog.ui

+6-10
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,13 @@
179179
<widget class="QComboBox" name="comboStyle"/>
180180
</item>
181181
<item row="2" column="2">
182-
<spacer name="spacerStyle">
183-
<property name="orientation">
184-
<enum>Qt::Orientation::Horizontal</enum>
185-
</property>
186-
<property name="sizeHint" stdset="0">
187-
<size>
188-
<width>40</width>
189-
<height>20</height>
190-
</size>
182+
<widget class="QLabel" name="labelStyleHint">
183+
<property name="font">
184+
<font>
185+
<italic>true</italic>
186+
</font>
191187
</property>
192-
</spacer>
188+
</widget>
193189
</item>
194190
<item row="3" column="0">
195191
<widget class="QLabel" name="labelColorScheme">

src/gui/uithememanager.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
#include <QStyle>
3838
#include <QStyleHints>
3939

40-
#ifdef Q_OS_WIN
41-
#include <QOperatingSystemVersion>
42-
#endif
43-
4440
#include "base/global.h"
4541
#include "base/logger.h"
4642
#include "base/path.h"
@@ -88,9 +84,11 @@ UIThemeManager::UIThemeManager()
8884
#endif
8985
{
9086
#ifdef Q_OS_WIN
91-
const QString defaultStyle = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10) ? u"Fusion"_s : QString();
92-
if (const QString styleName = Preferences::instance()->getStyle(); !QApplication::setStyle(styleName.isEmpty() ? defaultStyle : styleName))
93-
LogMsg(tr("Set app style failed. Unknown style: \"%1\"").arg(styleName), Log::WARNING);
87+
if (const QString styleName = Preferences::instance()->getStyle(); styleName.compare(u"system", Qt::CaseInsensitive) != 0)
88+
{
89+
if (!QApplication::setStyle(styleName.isEmpty() ? u"Fusion"_s : styleName))
90+
LogMsg(tr("Set app style failed. Unknown style: \"%1\"").arg(styleName), Log::WARNING);
91+
}
9492
#endif
9593

9694
#ifdef QBT_HAS_COLORSCHEME_OPTION

0 commit comments

Comments
 (0)