Skip to content

Commit 48acb14

Browse files
Allow to use Qt's default QStyle
Relevant prior PR qbittorrent#21553
1 parent 3d9e971 commit 48acb14

File tree

3 files changed

+98
-74
lines changed

3 files changed

+98
-74
lines changed

src/gui/optionsdialog.cpp

+24-5
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ void OptionsDialog::loadBehaviorTabOptions()
242242

243243
initializeStyleCombo();
244244

245+
#ifdef Q_OS_WIN
246+
m_ui->labelStyleHint->setText(tr("%1 is recommended for best compatibility with Windows dark mode", "Fusion is recommended for best compatibility with Windows dark mode").arg(u"Fusion"_s));
247+
#endif
248+
245249
m_ui->checkUseCustomTheme->setChecked(Preferences::instance()->useCustomUITheme());
246250
m_ui->customThemeFilePath->setSelectedPath(Preferences::instance()->customUIThemePath());
247251
m_ui->customThemeFilePath->setMode(FileSystemPathEdit::Mode::FileOpen);
@@ -454,7 +458,10 @@ void OptionsDialog::saveBehaviorTabOptions() const
454458
pref->setLocale(locale);
455459

456460
#ifdef Q_OS_WIN
457-
pref->setStyle(m_ui->comboStyle->currentText());
461+
if (const auto sysVariant = m_ui->comboStyle->currentData(); sysVariant.isValid())
462+
pref->setStyle(m_ui->comboStyle->currentData().toString());
463+
else
464+
pref->setStyle(m_ui->comboStyle->currentText());
458465
#endif
459466

460467
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
@@ -1690,20 +1697,32 @@ void OptionsDialog::initializeStyleCombo()
16901697
const QString prefStyleName = Preferences::instance()->getStyle();
16911698
const QString selectedStyleName = prefStyleName.isEmpty() ? QApplication::style()->name() : prefStyleName;
16921699
QStringList styleNames = QStyleFactory::keys();
1693-
for (qsizetype i = 1, stylesCount = styleNames.size(); i < stylesCount; ++i)
1700+
1701+
if (selectedStyleName.compare(u"system"_s, Qt::CaseInsensitive) == 0)
16941702
{
1695-
if (selectedStyleName.compare(styleNames.at(i), Qt::CaseInsensitive) == 0)
1703+
m_ui->comboStyle->addItem(tr("System", "System default QtStyle"), u"system"_s);
1704+
}
1705+
else
1706+
{
1707+
for (qsizetype i = 0, stylesCount = styleNames.size(); i < stylesCount; ++i)
16961708
{
1697-
styleNames.swapItemsAt(0, i);
1698-
break;
1709+
if (selectedStyleName.compare(styleNames.at(i), Qt::CaseInsensitive) == 0)
1710+
{
1711+
m_ui->comboStyle->addItem(styleNames.takeAt(i));
1712+
m_ui->comboStyle->addItem(tr("System", "System default QtStyle"), u"system"_s);
1713+
break;
1714+
}
16991715
}
17001716
}
1717+
17011718
m_ui->comboStyle->addItems(styleNames);
17021719
#else
17031720
m_ui->labelStyle->hide();
17041721
m_ui->comboStyle->hide();
1722+
m_ui->labelStyleHint->hide();
17051723
m_ui->UISettingsBoxLayout->removeWidget(m_ui->labelStyle);
17061724
m_ui->UISettingsBoxLayout->removeWidget(m_ui->comboStyle);
1725+
m_ui->UISettingsBoxLayout->removeWidget(m_ui->labelStyleHint);
17071726
m_ui->UISettingsBoxLayout->removeItem(m_ui->spacerStyle);
17081727
#endif
17091728
}

src/gui/optionsdialog.ui

+69-62
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<x>0</x>
124124
<y>0</y>
125125
<width>504</width>
126-
<height>1064</height>
126+
<height>1147</height>
127127
</rect>
128128
</property>
129129
<layout class="QVBoxLayout" name="verticalLayout_9">
@@ -133,17 +133,8 @@
133133
<string>Interface</string>
134134
</property>
135135
<layout class="QGridLayout" name="UISettingsBoxLayout">
136-
<item row="0" column="0" colspan="3">
137-
<widget class="QLabel" name="labelRestartRequired">
138-
<property name="font">
139-
<font>
140-
<italic>true</italic>
141-
</font>
142-
</property>
143-
<property name="text">
144-
<string>Changing Interface settings requires application restart</string>
145-
</property>
146-
</widget>
136+
<item row="2" column="1">
137+
<widget class="QComboBox" name="comboStyle"/>
147138
</item>
148139
<item row="1" column="0">
149140
<widget class="QLabel" name="labelLanguage">
@@ -152,10 +143,36 @@
152143
</property>
153144
</widget>
154145
</item>
155-
<item row="1" column="1">
156-
<widget class="QComboBox" name="comboLanguage"/>
146+
<item row="4" column="0" colspan="2">
147+
<widget class="QCheckBox" name="checkUseSystemIcon">
148+
<property name="text">
149+
<string>Use icons from system theme</string>
150+
</property>
151+
</widget>
157152
</item>
158-
<item row="1" column="2">
153+
<item row="3" column="0" colspan="4">
154+
<widget class="QGroupBox" name="checkUseCustomTheme">
155+
<property name="title">
156+
<string>Use custom UI Theme</string>
157+
</property>
158+
<property name="checkable">
159+
<bool>true</bool>
160+
</property>
161+
<layout class="QHBoxLayout" name="horizontalLayout_18">
162+
<item>
163+
<widget class="QLabel" name="label_16">
164+
<property name="text">
165+
<string>UI Theme file:</string>
166+
</property>
167+
</widget>
168+
</item>
169+
<item>
170+
<widget class="FileSystemPathLineEdit" name="customThemeFilePath" native="true"/>
171+
</item>
172+
</layout>
173+
</widget>
174+
</item>
175+
<item row="1" column="3">
159176
<spacer name="spacerLanguage">
160177
<property name="orientation">
161178
<enum>Qt::Orientation::Horizontal</enum>
@@ -175,10 +192,29 @@
175192
</property>
176193
</widget>
177194
</item>
178-
<item row="2" column="1">
179-
<widget class="QComboBox" name="comboStyle"/>
195+
<item row="0" column="0" colspan="4">
196+
<widget class="QLabel" name="labelRestartRequired">
197+
<property name="font">
198+
<font>
199+
<italic>true</italic>
200+
</font>
201+
</property>
202+
<property name="text">
203+
<string>Changing Interface settings requires application restart</string>
204+
</property>
205+
</widget>
180206
</item>
181-
<item row="2" column="2">
207+
<item row="5" column="0" colspan="2">
208+
<widget class="QPushButton" name="buttonCustomizeUITheme">
209+
<property name="text">
210+
<string>Customize UI Theme...</string>
211+
</property>
212+
</widget>
213+
</item>
214+
<item row="1" column="1">
215+
<widget class="QComboBox" name="comboLanguage"/>
216+
</item>
217+
<item row="2" column="3">
182218
<spacer name="spacerStyle">
183219
<property name="orientation">
184220
<enum>Qt::Orientation::Horizontal</enum>
@@ -191,39 +227,10 @@
191227
</property>
192228
</spacer>
193229
</item>
194-
<item row="3" column="0" colspan="3">
195-
<widget class="QGroupBox" name="checkUseCustomTheme">
196-
<property name="title">
197-
<string>Use custom UI Theme</string>
198-
</property>
199-
<property name="checkable">
200-
<bool>true</bool>
201-
</property>
202-
<layout class="QHBoxLayout" name="horizontalLayout_18">
203-
<item>
204-
<widget class="QLabel" name="label_16">
205-
<property name="text">
206-
<string>UI Theme file:</string>
207-
</property>
208-
</widget>
209-
</item>
210-
<item>
211-
<widget class="FileSystemPathLineEdit" name="customThemeFilePath" native="true"/>
212-
</item>
213-
</layout>
214-
</widget>
215-
</item>
216-
<item row="4" column="0" colspan="2">
217-
<widget class="QCheckBox" name="checkUseSystemIcon">
218-
<property name="text">
219-
<string>Use icons from system theme</string>
220-
</property>
221-
</widget>
222-
</item>
223-
<item row="5" column="0" colspan="2">
224-
<widget class="QPushButton" name="buttonCustomizeUITheme">
230+
<item row="2" column="2">
231+
<widget class="QLabel" name="labelStyleHint">
225232
<property name="text">
226-
<string>Customize UI Theme...</string>
233+
<string notr="true">labelStyleHint</string>
227234
</property>
228235
</widget>
229236
</item>
@@ -845,8 +852,8 @@
845852
<rect>
846853
<x>0</x>
847854
<y>0</y>
848-
<width>539</width>
849-
<height>1457</height>
855+
<width>538</width>
856+
<height>1588</height>
850857
</rect>
851858
</property>
852859
<layout class="QVBoxLayout" name="verticalLayout">
@@ -1681,8 +1688,8 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
16811688
<rect>
16821689
<x>0</x>
16831690
<y>0</y>
1684-
<width>504</width>
1685-
<height>848</height>
1691+
<width>378</width>
1692+
<height>839</height>
16861693
</rect>
16871694
</property>
16881695
<layout class="QVBoxLayout" name="verticalLayout_20">
@@ -2257,8 +2264,8 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
22572264
<rect>
22582265
<x>0</x>
22592266
<y>0</y>
2260-
<width>302</width>
2261-
<height>408</height>
2267+
<width>303</width>
2268+
<height>402</height>
22622269
</rect>
22632270
</property>
22642271
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -2606,8 +2613,8 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
26062613
<rect>
26072614
<x>0</x>
26082615
<y>0</y>
2609-
<width>413</width>
2610-
<height>693</height>
2616+
<width>458</width>
2617+
<height>709</height>
26112618
</rect>
26122619
</property>
26132620
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -3155,8 +3162,8 @@ Disable encryption: Only connect to peers without protocol encryption</string>
31553162
<rect>
31563163
<x>0</x>
31573164
<y>0</y>
3158-
<width>336</width>
3159-
<height>391</height>
3165+
<width>360</width>
3166+
<height>416</height>
31603167
</rect>
31613168
</property>
31623169
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -3345,8 +3352,8 @@ Disable encryption: Only connect to peers without protocol encryption</string>
33453352
<rect>
33463353
<x>0</x>
33473354
<y>0</y>
3348-
<width>382</width>
3349-
<height>1045</height>
3355+
<width>434</width>
3356+
<height>1102</height>
33503357
</rect>
33513358
</property>
33523359
<layout class="QVBoxLayout" name="verticalLayout_23">

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"
@@ -85,9 +81,11 @@ UIThemeManager::UIThemeManager()
8581
#endif
8682
{
8783
#ifdef Q_OS_WIN
88-
const QString defaultStyle = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10) ? u"Fusion"_s : QString();
89-
if (const QString styleName = Preferences::instance()->getStyle(); !QApplication::setStyle(styleName.isEmpty() ? defaultStyle : styleName))
90-
LogMsg(tr("Set app style failed. Unknown style: \"%1\"").arg(styleName), Log::WARNING);
84+
if (const QString styleName = Preferences::instance()->getStyle(); styleName.compare(u"system", Qt::CaseInsensitive) != 0)
85+
{
86+
if (!QApplication::setStyle(styleName.isEmpty() ? u"Fusion"_s : styleName))
87+
LogMsg(tr("Set app style failed. Unknown style: \"%1\"").arg(styleName), Log::WARNING);
88+
}
9189
#endif
9290

9391
// NOTE: Qt::QueuedConnection can be omitted as soon as support for Qt 6.5 is dropped

0 commit comments

Comments
 (0)