qt: Update min/max width of OptionsDialog depending on buttons width

This commit is contained in:
xdustinface 2020-09-25 23:22:04 +02:00
parent b4ecfdce5a
commit d351fca6a6
3 changed files with 23 additions and 1 deletions

View File

@ -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<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)
{

View File

@ -64,6 +64,8 @@ private Q_SLOTS:
void updatePrivateSendVisibility();
void updateWidth();
Q_SIGNALS:
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);

View File

@ -1259,7 +1259,6 @@ OptionsDialog
******************************************************/
QDialog#OptionsDialog {
min-width: 585px;
}
QDialog#OptionsDialog QValueComboBox,