From d351fca6a6b099f02e36a478a3a2cbad0407560b Mon Sep 17 00:00:00 2001 From: xdustinface Date: Fri, 25 Sep 2020 23:22:04 +0200 Subject: [PATCH] qt: Update min/max width of OptionsDialog depending on buttons width --- src/qt/optionsdialog.cpp | 21 +++++++++++++++++++++ src/qt/optionsdialog.h | 2 ++ src/qt/res/css/general.css | 1 - 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 808da31bf1a71..495350951a122 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -168,6 +168,8 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : } }); #endif + + updateWidth(); } OptionsDialog::~OptionsDialog() @@ -237,6 +239,7 @@ void OptionsDialog::setModel(OptionsModel *_model) if (_model != nullptr) { _model->emitPrivateSendEnabledChanged(); } + updateWidth(); }); } @@ -434,6 +437,24 @@ void OptionsDialog::updatePrivateSendVisibility() ui->btnPrivateSend->setVisible(fEnabled); } +void OptionsDialog::updateWidth() +{ + int nWidthWidestButton{0}; + int nButtonsVisible{0}; + for (QAbstractButton* button : pageButtons.buttons()) { + if (!button->isVisible()) { + continue; + } + QFontMetrics fm(button->font()); + nWidthWidestButton = std::max(nWidthWidestButton, fm.width(button->text())); + ++nButtonsVisible; + } + // Add 10 per button as padding and use minimum 585 which is what we used in css before + int nWidth = std::max(585, (nWidthWidestButton + 10) * nButtonsVisible); + setMinimumWidth(nWidth); + setMaximumWidth(nWidth); +} + ProxyAddressValidator::ProxyAddressValidator(QObject *parent) : QValidator(parent) { diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 7fdbe7fff7dac..c6287de7960c9 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -64,6 +64,8 @@ private Q_SLOTS: void updatePrivateSendVisibility(); + void updateWidth(); + Q_SIGNALS: void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index a2a6484564438..8adb3ae796594 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -1259,7 +1259,6 @@ OptionsDialog ******************************************************/ QDialog#OptionsDialog { - min-width: 585px; } QDialog#OptionsDialog QValueComboBox,