Skip to content

Commit cd42553

Browse files
committed
Merge #15040: qt: Add workaround for QProgressDialog bug on macOS
7c572c4 Add workaround for QProgressDialog bug on macOS (Hennadii Stepanov) Pull request description: Fix #15016. Refs: - [QTBUG-65750: QProgressDialog too small width at larger font size on Mac](https://bugreports.qt.io/browse/QTBUG-65750) - [QTBUG-70357: QProgressDialog is too narrow to fit the text of its label](https://bugreports.qt.io/browse/QTBUG-70357) With this PR: ![screenshot from 2018-12-26 22-01-30](https://user-images.githubusercontent.com/32963518/50456571-1aa35b80-095e-11e9-8442-c285555f2bee.png) Tree-SHA512: dde668dfa7d2144973c0e868aea7fdb7d90f78584836d024ffefb8df4a709d6842fa3601954759b4462856a80e81df15b861ea39506599230a16928b621d9f8f
2 parents 12b3010 + 7c572c4 commit cd42553

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

src/qt/bitcoingui.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,25 +1245,21 @@ void BitcoinGUI::detectShutdown()
12451245

12461246
void BitcoinGUI::showProgress(const QString &title, int nProgress)
12471247
{
1248-
if (nProgress == 0)
1249-
{
1250-
progressDialog = new QProgressDialog(title, "", 0, 100);
1248+
if (nProgress == 0) {
1249+
progressDialog = new QProgressDialog(title, QString(), 0, 100);
1250+
GUIUtil::PolishProgressDialog(progressDialog);
12511251
progressDialog->setWindowModality(Qt::ApplicationModal);
12521252
progressDialog->setMinimumDuration(0);
1253-
progressDialog->setCancelButton(nullptr);
12541253
progressDialog->setAutoClose(false);
12551254
progressDialog->setValue(0);
1256-
}
1257-
else if (nProgress == 100)
1258-
{
1259-
if (progressDialog)
1260-
{
1255+
} else if (nProgress == 100) {
1256+
if (progressDialog) {
12611257
progressDialog->close();
12621258
progressDialog->deleteLater();
12631259
}
1264-
}
1265-
else if (progressDialog)
1260+
} else if (progressDialog) {
12661261
progressDialog->setValue(nProgress);
1262+
}
12671263
}
12681264

12691265
void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)

src/qt/guiutil.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@
4848
#include <QFileDialog>
4949
#include <QFont>
5050
#include <QFontDatabase>
51+
#include <QFontMetrics>
5152
#include <QKeyEvent>
5253
#include <QLineEdit>
54+
#include <QMouseEvent>
55+
#include <QProgressDialog>
5356
#include <QSettings>
5457
#include <QTextDocument> // for Qt::mightBeRichText
5558
#include <QThread>
5659
#include <QUrlQuery>
57-
#include <QMouseEvent>
5860

5961
#if defined(Q_OS_MAC)
6062
#pragma GCC diagnostic push
@@ -933,4 +935,16 @@ bool ItemDelegate::eventFilter(QObject *object, QEvent *event)
933935
return QItemDelegate::eventFilter(object, event);
934936
}
935937

938+
void PolishProgressDialog(QProgressDialog* dialog)
939+
{
940+
#ifdef Q_OS_MAC
941+
// Workaround for macOS-only Qt bug; see: QTBUG-65750, QTBUG-70357.
942+
const int margin = dialog->fontMetrics().width("X");
943+
dialog->resize(dialog->width() + 2 * margin, dialog->height());
944+
dialog->show();
945+
#else
946+
Q_UNUSED(dialog);
947+
#endif
948+
}
949+
936950
} // namespace GUIUtil

src/qt/guiutil.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class QAbstractItemView;
3131
class QDateTime;
3232
class QFont;
3333
class QLineEdit;
34+
class QProgressDialog;
3435
class QUrl;
3536
class QWidget;
3637
QT_END_NAMESPACE
@@ -248,6 +249,9 @@ namespace GUIUtil
248249
private:
249250
bool eventFilter(QObject *object, QEvent *event);
250251
};
252+
253+
// Fix known bugs in QProgressDialog class.
254+
void PolishProgressDialog(QProgressDialog* dialog);
251255
} // namespace GUIUtil
252256

253257
#endif // BITCOIN_QT_GUIUTIL_H

src/qt/walletview.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,24 +305,19 @@ void WalletView::usedReceivingAddresses()
305305

306306
void WalletView::showProgress(const QString &title, int nProgress)
307307
{
308-
if (nProgress == 0)
309-
{
310-
progressDialog = new QProgressDialog(title, "", 0, 100);
308+
if (nProgress == 0) {
309+
progressDialog = new QProgressDialog(title, tr("Cancel"), 0, 100);
310+
GUIUtil::PolishProgressDialog(progressDialog);
311311
progressDialog->setWindowModality(Qt::ApplicationModal);
312312
progressDialog->setMinimumDuration(0);
313313
progressDialog->setAutoClose(false);
314314
progressDialog->setValue(0);
315-
progressDialog->setCancelButtonText(tr("Cancel"));
316-
}
317-
else if (nProgress == 100)
318-
{
319-
if (progressDialog)
320-
{
315+
} else if (nProgress == 100) {
316+
if (progressDialog) {
321317
progressDialog->close();
322318
progressDialog->deleteLater();
323319
}
324-
}
325-
else if (progressDialog) {
320+
} else if (progressDialog) {
326321
if (progressDialog->wasCanceled()) {
327322
getWalletModel()->wallet().abortRescan();
328323
} else {

0 commit comments

Comments
 (0)