Skip to content

Commit

Permalink
qt: Update min/max width of OptionsDialog depending on buttons width
Browse files Browse the repository at this point in the history
  • Loading branch information
xdustinface committed Sep 28, 2020
1 parent b4ecfdc commit d351fca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
}
});
#endif

updateWidth();
}

OptionsDialog::~OptionsDialog()
Expand Down Expand Up @@ -237,6 +239,7 @@ void OptionsDialog::setModel(OptionsModel *_model)
if (_model != nullptr) {
_model->emitPrivateSendEnabledChanged();
}
updateWidth();
});
}

Expand Down Expand Up @@ -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<int>(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<int>(585, (nWidthWidestButton + 10) * nButtonsVisible);
setMinimumWidth(nWidth);
setMaximumWidth(nWidth);
}

ProxyAddressValidator::ProxyAddressValidator(QObject *parent) :
QValidator(parent)
{
Expand Down
2 changes: 2 additions & 0 deletions src/qt/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private Q_SLOTS:

void updatePrivateSendVisibility();

void updateWidth();

Q_SIGNALS:
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);

Expand Down
1 change: 0 additions & 1 deletion src/qt/res/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,6 @@ OptionsDialog
******************************************************/

QDialog#OptionsDialog {
min-width: 585px;
}

QDialog#OptionsDialog QValueComboBox,
Expand Down

0 comments on commit d351fca

Please sign in to comment.