Skip to content

Commit c0447b0

Browse files
committed
qt: Resize main toolbar depending on visible buttons / font attributes
1 parent 3a8d9a4 commit c0447b0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/qt/bitcoingui.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,9 @@ void BitcoinGUI::optionsClicked()
924924

925925
OptionsDialog dlg(this, enableWallet);
926926
dlg.setModel(clientModel->getOptionsModel());
927+
connect(&dlg, &OptionsDialog::appearanceChanged, [=]() {
928+
updateWidth();
929+
});
927930
dlg.exec();
928931

929932
updatePrivateSendVisibility();
@@ -1171,6 +1174,26 @@ void BitcoinGUI::updatePrivateSendVisibility()
11711174
privateSendCoinsMenuAction->setVisible(fEnabled);
11721175
showPrivateSendHelpAction->setVisible(fEnabled);
11731176
updateToolBarShortcuts();
1177+
updateWidth();
1178+
}
1179+
1180+
void BitcoinGUI::updateWidth()
1181+
{
1182+
int nWidthWidestButton{0};
1183+
int nButtonsVisible{0};
1184+
for (QAbstractButton* button : tabGroup->buttons()) {
1185+
if (!button->isEnabled()) {
1186+
continue;
1187+
}
1188+
QFontMetrics fm(button->font());
1189+
nWidthWidestButton = std::max<int>(nWidthWidestButton, fm.width(button->text()));
1190+
++nButtonsVisible;
1191+
}
1192+
// Add 30 per button as padding and use minimum 980 which is the minimum required to show all tab's contents
1193+
// Use nButtonsVisible + 1 <- for the dash logo
1194+
int nWidth = std::max<int>(980, (nWidthWidestButton + 30) * (nButtonsVisible + 1));
1195+
setMinimumWidth(nWidth);
1196+
setMaximumWidth(nWidth);
11741197
}
11751198

11761199
void BitcoinGUI::updateToolBarShortcuts()
@@ -1490,6 +1513,10 @@ void BitcoinGUI::showEvent(QShowEvent *event)
14901513
openRepairAction->setEnabled(true);
14911514
aboutAction->setEnabled(true);
14921515
optionsAction->setEnabled(true);
1516+
1517+
if (!event->spontaneous()) {
1518+
updateWidth();
1519+
}
14931520
}
14941521

14951522
#ifdef ENABLE_WALLET

src/qt/bitcoingui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ private Q_SLOTS:
331331
void showModalOverlay();
332332

333333
void updatePrivateSendVisibility();
334+
335+
void updateWidth();
334336
};
335337

336338
class UnitDisplayStatusBarControl : public QLabel

0 commit comments

Comments
 (0)