From 76151110e57325f75e18cd4b9c3ba8316f8bf7a3 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Sat, 11 Jan 2025 10:17:38 +0300 Subject: [PATCH] Handle Qt style options uniformly PR #22133. Closes #22061. --- src/gui/optionsdialog.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 13e9148fc071..676612146589 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2023-2024 Vladimir Golovnev + * Copyright (C) 2023-2025 Vladimir Golovnev * Copyright (C) 2024 Jonathan Ketchker * Copyright (C) 2006 Christophe Dumez * @@ -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 @@ -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()); - 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();