Skip to content

Commit

Permalink
Qt scaling fix (#1437)
Browse files Browse the repository at this point in the history
* Implement qt scaling fixes

* Adjust toolbar widget sizes dynamically

* Adjust component sizing dynamically on Masternode and Transaction pages.

* Adjust instantsendWidget width to be dynamic in TransactionView

* Bug fixes and dynamic text scaling

* Enhance UI scalability by adding dynamic text resizing across various pages

* Update font size and set minimum label width for readability.

* Update dynamic scaling
  • Loading branch information
firstcryptoman authored Jun 18, 2024
1 parent 290730d commit fa6a50c
Show file tree
Hide file tree
Showing 14 changed files with 475 additions and 9 deletions.
27 changes: 25 additions & 2 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void BitcoinGUI::createToolBars()
{
if(walletFrame)
{
QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
toolbar = addToolBar(tr("Tabs toolbar"));
toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
toolbar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
toolbar->setToolButtonStyle(Qt::ToolButtonTextOnly);
Expand All @@ -523,7 +523,7 @@ void BitcoinGUI::createToolBars()
toolbar->addAction(lelantusAction);
toolbar->addAction(masternodeAction);

QLabel *logoLabel = new QLabel();
logoLabel = new QLabel();
logoLabel->setObjectName("lblToolbarLogo");
logoLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

Expand Down Expand Up @@ -1474,3 +1474,26 @@ void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
optionsModel->setDisplayUnit(action->data());
}
}

// Handles resize events for the BitcoinGUI widget by adjusting internal component sizes.
void BitcoinGUI::resizeEvent(QResizeEvent* event) {
QMainWindow::resizeEvent(event);

// Retrieve new dimensions from the resize event
int newWidth = event->size().width();
int newHeight = event->size().height();
int actionWidth = newWidth / 6;

// Set widths for each action dynamically
QWidget* overviewWidget = toolbar->widgetForAction(overviewAction);
QWidget* receiveWidget = toolbar->widgetForAction(receiveCoinsAction);
QWidget* historyWidget = toolbar->widgetForAction(historyAction);
QWidget* sendCoinsWidget = toolbar->widgetForAction(sendCoinsAction);
QWidget* masternodeWidget = toolbar->widgetForAction(masternodeAction);

overviewWidget->setMinimumWidth(actionWidth);
receiveWidget->setMinimumWidth(actionWidth);
historyWidget->setMinimumWidth(actionWidth);
sendCoinsWidget->setMinimumWidth(actionWidth);
masternodeWidget->setMinimumWidth(actionWidth);
}
6 changes: 5 additions & 1 deletion src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <QMenu>
#include <QPoint>
#include <QSystemTrayIcon>
#include <QPushButton>
#include <QWidget>

class ClientModel;
class NetworkStyle;
Expand Down Expand Up @@ -121,7 +123,8 @@ class BitcoinGUI : public QMainWindow
QAction *lelantusAction;
QAction *masternodeAction;
QAction *logoAction;

QToolBar *toolbar;
QLabel *logoLabel;
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
Notificator *notificator;
Expand All @@ -141,6 +144,7 @@ class BitcoinGUI : public QMainWindow
void createMenuBar();
/** Create the toolbars */
void createToolBars();
void resizeEvent(QResizeEvent*);
/** Create system tray icon and notification */
void createTrayIcon(const NetworkStyle *networkStyle);
/** Create system tray menu (or setup the dock menu) */
Expand Down
45 changes: 45 additions & 0 deletions src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,48 @@ void MasternodeList::copyCollateralOutpoint_clicked()

QApplication::clipboard()->setText(QString::fromStdString(dmn->collateralOutpoint.ToStringShort()));
}

void MasternodeList::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);

const int newWidth = event->size().width();
const int newHeight = event->size().height();

adjustTextSize(newWidth ,newHeight);

// Calculate new column widths based on the new window width
int newWidthOwner = static_cast<int>(newWidth * 0.19);
int newWidthMin = static_cast<int>(newWidth * 0.08);
int newWidthMid = static_cast<int>(newWidth * 0.12);
int newWidthStatus = static_cast<int>(newWidth * 0.11);

// Apply new column widths
ui->tableWidgetMasternodesDIP3->setColumnWidth(0, newWidthStatus);
ui->tableWidgetMasternodesDIP3->setColumnWidth(1, newWidthMin);
ui->tableWidgetMasternodesDIP3->setColumnWidth(2, newWidthMin);
ui->tableWidgetMasternodesDIP3->setColumnWidth(3, newWidthMid);
ui->tableWidgetMasternodesDIP3->setColumnWidth(4, newWidthMid);
ui->tableWidgetMasternodesDIP3->setColumnWidth(5, newWidthMid);
ui->tableWidgetMasternodesDIP3->setColumnWidth(6, newWidthMid);
ui->tableWidgetMasternodesDIP3->setColumnWidth(7, newWidthMid);
ui->tableWidgetMasternodesDIP3->setColumnWidth(8, newWidthMid);
ui->tableWidgetMasternodesDIP3->setColumnWidth(9, newWidthOwner);
}
void MasternodeList::adjustTextSize(int width,int height){

const double fontSizeScalingFactor = 70.0;
int baseFontSize = std::min(width, height) / fontSizeScalingFactor;
int fontSize = std::min(15, std::max(12, baseFontSize));
QFont font = this->font();
font.setPointSize(fontSize);

// Set font size for all labels
ui->label_filter_2->setFont(font);
ui->label_count_2->setFont(font);
ui->countLabelDIP3->setFont(font);
ui->checkBoxMyMasternodesOnly->setFont(font);
ui->tableWidgetMasternodesDIP3->setFont(font);
ui->tableWidgetMasternodesDIP3->horizontalHeader()->setFont(font);
ui->tableWidgetMasternodesDIP3->verticalHeader()->setFont(font);
}
4 changes: 3 additions & 1 deletion src/qt/masternodelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QMenu>
#include <QTimer>
#include <QWidget>
#include <QResizeEvent>

#define MASTERNODELIST_UPDATE_SECONDS 3
#define MASTERNODELIST_FILTER_COOLDOWN_SECONDS 3
Expand Down Expand Up @@ -38,7 +39,8 @@ class MasternodeList : public QWidget

void setClientModel(ClientModel* clientModel);
void setWalletModel(WalletModel* walletModel);

void resizeEvent(QResizeEvent*) override;
void adjustTextSize(int width,int height);
private:
QMenu* contextMenuDIP3;
int64_t nTimeFilterUpdatedDIP3;
Expand Down
100 changes: 100 additions & 0 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,104 @@ void MigrateLelantusToSparkDialog::onMigrateClicked()
bool MigrateLelantusToSparkDialog::getClickedButton()
{
return clickedButton;
}
void OverviewPage::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);

// Retrieve new dimensions from the resize event
const int newWidth = event->size().width();
const int newHeight = event->size().height();
adjustTextSize(newWidth, newHeight);

// Determine widths for specific widgets as percentages of total width
int labelWidth = static_cast<int>(newWidth * 0.5);
int labelMinWidth = static_cast<int>(newWidth * 0.15);
int labelMaxWidth = static_cast<int>(newWidth * 0.35);
const int labelHeight = 20;

// Configure the dimensions and constraints of each widget
ui->labelBalance->setFixedWidth(labelWidth);
ui->labelBalance->setMinimumWidth(labelMinWidth);
ui->labelBalance->setMaximumWidth(labelMaxWidth);
ui->labelBalance->setFixedHeight(labelHeight);

ui->labelUnconfirmed->setFixedWidth(labelWidth);
ui->labelUnconfirmed->setMinimumWidth(labelMinWidth);
ui->labelUnconfirmed->setMaximumWidth(labelMaxWidth);
ui->labelUnconfirmed->setFixedHeight(labelHeight);

int buttonWidth = static_cast<int>(newWidth * 0.15);
int buttonHeight = static_cast<int>(newHeight * 0.05);
int buttonMinHeight = static_cast<int>(20);
int buttonMaxHeight = static_cast<int>(45);

ui->anonymizeButton->setMinimumWidth(buttonWidth);
ui->anonymizeButton->setMaximumWidth(buttonWidth * 2);
ui->anonymizeButton->setMinimumHeight(buttonMinHeight);
ui->anonymizeButton->setMaximumHeight(buttonMaxHeight);

// Set the minimum width for all label widgets to ensure they maintain a consistent and readable size regardless of window resizing
ui->labelAnonymizable->setMinimumWidth(labelMinWidth);
ui->labelAlerts->setMinimumWidth(labelMinWidth);
ui->label->setMinimumWidth(labelMinWidth);
ui->labelWatchPending->setMinimumWidth(labelMinWidth);
ui->labelBalance->setMinimumWidth(labelMinWidth);
ui->labelSpendable->setMinimumWidth(labelMinWidth);
ui->labelWatchAvailable->setMinimumWidth(labelMinWidth);
ui->labelUnconfirmedPrivate->setMinimumWidth(labelMinWidth);
ui->labelWatchonly->setMinimumWidth(labelMinWidth);
ui->labelTotal->setMinimumWidth(labelMinWidth);
ui->labelWatchTotal->setMinimumWidth(labelMinWidth);
ui->labelUnconfirmed->setMinimumWidth(labelMinWidth);
ui->labelImmature->setMinimumWidth(labelMinWidth);
ui->labelPrivate->setMinimumWidth(labelMinWidth);
ui->label_4->setMinimumWidth(labelMinWidth);
}
void OverviewPage::adjustTextSize(int width, int height){

const double fontSizeScalingFactor = 133.0;
int baseFontSize = width / fontSizeScalingFactor;
int fontSize = std::min(15, std::max(12, baseFontSize));

// Font for regular text components(not bold)
QFont textFont = ui->labelBalance->font();
textFont.setPointSize(fontSize);
textFont.setBold(false);

// Font for text components that should be bold
QFont labelFont = textFont;
labelFont.setBold(true);

ui->textWarning1->setFont(textFont);
ui->textWarning2->setFont(textFont);
ui->labelWalletStatus->setFont(textFont);
ui->anonymizeButton->setFont(textFont);

// Apply label font to all label components
ui->labelAlerts->setFont(labelFont);
ui->label_5->setFont(labelFont);
ui->labelAnonymizableText->setFont(textFont);
ui->label->setFont(labelFont);
ui->labelAnonymizable->setFont(labelFont);
ui->labelWatchPending->setFont(labelFont);
ui->labelBalance->setFont(labelFont);
ui->labelSpendable->setFont(labelFont);
ui->labelWatchAvailable->setFont(labelFont);
ui->labelPendingText->setFont(textFont);
ui->labelUnconfirmedPrivate->setFont(labelFont);
ui->labelUnconfirmedPrivateText->setFont(textFont);
ui->labelTotalText->setFont(textFont);
ui->labelWatchonly->setFont(labelFont);
ui->labelBalanceText->setFont(textFont);
ui->labelTotal->setFont(labelFont);
ui->labelWatchTotal->setFont(labelFont);
ui->labelUnconfirmed->setFont(labelFont);
ui->labelImmatureText->setFont(textFont);
ui->labelImmature->setFont(labelFont);
ui->labelWatchImmature->setFont(labelFont);
ui->labelPrivateText->setFont(textFont);
ui->labelPrivate->setFont(labelFont);
ui->label_4->setFont(labelFont);

}
5 changes: 4 additions & 1 deletion src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <QSettings>
#include <QMessageBox>
#include <QTimer>
#include <QResizeEvent>


class ClientModel;
class TransactionFilterProxy;
Expand Down Expand Up @@ -44,6 +46,7 @@ class OverviewPage : public QWidget
void setWalletModel(WalletModel *walletModel);
void showOutOfSyncWarning(bool fShow);
void UpdatePropertyBalance(unsigned int propertyId, uint64_t available, uint64_t reserved);
void resizeEvent(QResizeEvent* event) override;

public Q_SLOTS:
void on_anonymizeButton_clicked();
Expand Down Expand Up @@ -89,7 +92,7 @@ public Q_SLOTS:
QString migrationWindowClosesIn;
QString blocksRemaining;
QString migrateAmount;

void adjustTextSize(int width,int height);
private Q_SLOTS:
void updateDisplayUnit();
void handleTransactionClicked(const QModelIndex &index);
Expand Down
95 changes: 95 additions & 0 deletions src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QComboBox>
#include <QPushButton>
#include <QButtonGroup>
#include <QScreen>

ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -360,4 +361,98 @@ void RecentRequestsFilterProxy::setTypeFilter(quint32 modes)
{
this->typeFilter = modes;
invalidateFilter();
}

// Handles resize events for the ReceiveCoinsDialog widget by adjusting internal component sizes.
void ReceiveCoinsDialog::resizeEvent(QResizeEvent* event)
{
QDialog::resizeEvent(event);

// Get new size from the event
const int newWidth = event->size().width();
const int newHeight = event->size().height();

adjustTextSize(newWidth,newHeight);
// Set fixed, minimum, and maximum sizes for ComboBoxes
int comboBoxMinHeight = 20;
int comboBoxMaxHeight = 40;
int comboBoxWidth = newWidth * 0.08;
int comboBoxMinWidth = newWidth * 0.05;
int comboBoxMaxWidth = newWidth * 0.1;

ui->addressTypeCombobox->setMinimumWidth(comboBoxMinWidth);
ui->addressTypeCombobox->setMaximumWidth(comboBoxMaxWidth);
ui->addressTypeCombobox->setMinimumHeight(comboBoxMinHeight);
ui->addressTypeCombobox->setMaximumHeight(comboBoxMaxHeight);

ui->addressTypeHistoryCombobox->setMinimumWidth(comboBoxMinWidth);
ui->addressTypeHistoryCombobox->setMaximumWidth(comboBoxMaxWidth);
ui->addressTypeHistoryCombobox->setMinimumHeight(comboBoxMinHeight);
ui->addressTypeHistoryCombobox->setMaximumHeight(comboBoxMaxHeight);

// Set sizes for buttons dynamically
int buttonMinHeight = 20;
int buttonMaxHeight = 35;
int buttonWidth = newWidth * 0.15;
int buttonMinWidth = newWidth * 0.1;
int buttonMaxWidth = newWidth * 0.4;

ui->clearButton->setMinimumWidth(buttonMinWidth);
ui->clearButton->setMaximumWidth(buttonMaxWidth);
ui->clearButton->setMinimumHeight(buttonMinHeight);
ui->clearButton->setMaximumHeight(buttonMaxHeight);

ui->receiveButton->setMinimumWidth(buttonMinWidth);
ui->receiveButton->setMaximumWidth(buttonMaxWidth);
ui->receiveButton->setMinimumHeight(buttonMinHeight);
ui->receiveButton->setMaximumHeight(buttonMaxHeight);

ui->showRequestButton->setMinimumWidth(buttonMinWidth);
ui->showRequestButton->setMaximumWidth(buttonMaxWidth);
ui->showRequestButton->setMinimumHeight(buttonMinHeight);
ui->showRequestButton->setMaximumHeight(buttonMaxHeight);

ui->removeRequestButton->setMinimumWidth(buttonMinWidth);
ui->removeRequestButton->setMaximumWidth(buttonMaxWidth);
ui->removeRequestButton->setMinimumHeight(buttonMinHeight);
ui->removeRequestButton->setMaximumHeight(buttonMaxHeight);

// Adjust column widths proportionally
int dateColumnWidth = newWidth * 0.25;
int labelColumnWidth = newWidth * 0.25;
int addressTypeColumnWidth = newWidth * 0.25;
int amountColumnWidth = newWidth * 0.25;

ui->recentRequestsView->setColumnWidth(RecentRequestsTableModel::Date, dateColumnWidth);
ui->recentRequestsView->setColumnWidth(RecentRequestsTableModel::Label, labelColumnWidth);
ui->recentRequestsView->setColumnWidth(RecentRequestsTableModel::AddressType, addressTypeColumnWidth);
ui->recentRequestsView->setColumnWidth(RecentRequestsTableModel::Amount, amountColumnWidth);
}
void ReceiveCoinsDialog::adjustTextSize(int width,int height){

const double fontSizeScalingFactor = 70.0;
int baseFontSize = std::min(width, height) / fontSizeScalingFactor;
int fontSize = std::min(15, std::max(12, baseFontSize));
QFont font = this->font();
font.setPointSize(fontSize);

// Set font size for all labels
ui->reuseAddress->setFont(font);
ui->label_4->setFont(font);
ui->label_3->setFont(font);
ui->addressTypeLabel->setFont(font);
ui->label_5->setFont(font);
ui->label_2->setFont(font);
ui->label->setFont(font);
ui->label_7->setFont(font);
ui->label_6->setFont(font);
ui->receiveButton->setFont(font);
ui->clearButton->setFont(font);
ui->showRequestButton->setFont(font);
ui->removeRequestButton->setFont(font);
ui->addressTypeCombobox->setFont(font);
ui->addressTypeHistoryCombobox->setFont(font);
ui->recentRequestsView->setFont(font);
ui->recentRequestsView->horizontalHeader()->setFont(font);
ui->recentRequestsView->verticalHeader()->setFont(font);
}
Loading

0 comments on commit fa6a50c

Please sign in to comment.