Skip to content

Commit

Permalink
Handle Qt style options uniformly
Browse files Browse the repository at this point in the history
PR #22133.
Closes #22061.
  • Loading branch information
glassez authored Jan 11, 2025
1 parent 5875d8b commit 7615111
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2023-2024 Vladimir Golovnev <[email protected]>
* Copyright (C) 2023-2025 Vladimir Golovnev <[email protected]>
* Copyright (C) 2024 Jonathan Ketchker
* Copyright (C) 2006 Christophe Dumez <[email protected]>
*
Expand Down Expand Up @@ -464,10 +464,7 @@ void OptionsDialog::saveBehaviorTabOptions() const
pref->setLocale(locale);

#ifdef Q_OS_WIN
if (const QVariant systemStyle = m_ui->comboStyle->currentData(); systemStyle.isValid())
pref->setStyle(systemStyle.toString());
else
pref->setStyle(m_ui->comboStyle->currentText());
pref->setStyle(m_ui->comboStyle->currentData().toString());
#endif

#ifdef QBT_HAS_COLORSCHEME_OPTION
Expand Down Expand Up @@ -1716,18 +1713,20 @@ void OptionsDialog::initializeStyleCombo()
{
#ifdef Q_OS_WIN
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));
, "Fusion is recommended for best compatibility with Windows dark mode").arg(u"Fusion"_s));
m_ui->comboStyle->addItem(tr("System", "System default Qt style"), u"system"_s);
m_ui->comboStyle->setItemData(0, tr("Let Qt decide the style for this system"), Qt::ToolTipRole);
m_ui->comboStyle->insertSeparator(1);

QStringList styleNames = QStyleFactory::keys();
std::sort(styleNames.begin(), styleNames.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
m_ui->comboStyle->addItems(styleNames);
for (const QString &styleName : asConst(styleNames))
m_ui->comboStyle->addItem(styleName, styleName);

const QString prefStyleName = Preferences::instance()->getStyle();
const QString selectedStyleName = prefStyleName.isEmpty() ? QApplication::style()->name() : prefStyleName;
m_ui->comboStyle->setCurrentIndex(m_ui->comboStyle->findText(selectedStyleName, Qt::MatchFixedString));
const int styleIndex = m_ui->comboStyle->findData(selectedStyleName, Qt::UserRole, Qt::MatchFixedString);
m_ui->comboStyle->setCurrentIndex(std::max(0, styleIndex));
#else
m_ui->labelStyle->hide();
m_ui->comboStyle->hide();
Expand Down

0 comments on commit 7615111

Please sign in to comment.