Skip to content

Commit

Permalink
Merge #15040: qt: Add workaround for QProgressDialog bug on macOS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonasschnelli committed Jan 17, 2019
2 parents 12b3010 + 7c572c4 commit cd42553
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
18 changes: 7 additions & 11 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,25 +1245,21 @@ void BitcoinGUI::detectShutdown()

void BitcoinGUI::showProgress(const QString &title, int nProgress)
{
if (nProgress == 0)
{
progressDialog = new QProgressDialog(title, "", 0, 100);
if (nProgress == 0) {
progressDialog = new QProgressDialog(title, QString(), 0, 100);
GUIUtil::PolishProgressDialog(progressDialog);
progressDialog->setWindowModality(Qt::ApplicationModal);
progressDialog->setMinimumDuration(0);
progressDialog->setCancelButton(nullptr);
progressDialog->setAutoClose(false);
progressDialog->setValue(0);
}
else if (nProgress == 100)
{
if (progressDialog)
{
} else if (nProgress == 100) {
if (progressDialog) {
progressDialog->close();
progressDialog->deleteLater();
}
}
else if (progressDialog)
} else if (progressDialog) {
progressDialog->setValue(nProgress);
}
}

void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
Expand Down
16 changes: 15 additions & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@
#include <QFileDialog>
#include <QFont>
#include <QFontDatabase>
#include <QFontMetrics>
#include <QKeyEvent>
#include <QLineEdit>
#include <QMouseEvent>
#include <QProgressDialog>
#include <QSettings>
#include <QTextDocument> // for Qt::mightBeRichText
#include <QThread>
#include <QUrlQuery>
#include <QMouseEvent>

#if defined(Q_OS_MAC)
#pragma GCC diagnostic push
Expand Down Expand Up @@ -933,4 +935,16 @@ bool ItemDelegate::eventFilter(QObject *object, QEvent *event)
return QItemDelegate::eventFilter(object, event);
}

void PolishProgressDialog(QProgressDialog* dialog)
{
#ifdef Q_OS_MAC
// Workaround for macOS-only Qt bug; see: QTBUG-65750, QTBUG-70357.
const int margin = dialog->fontMetrics().width("X");
dialog->resize(dialog->width() + 2 * margin, dialog->height());
dialog->show();
#else
Q_UNUSED(dialog);
#endif
}

} // namespace GUIUtil
4 changes: 4 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class QAbstractItemView;
class QDateTime;
class QFont;
class QLineEdit;
class QProgressDialog;
class QUrl;
class QWidget;
QT_END_NAMESPACE
Expand Down Expand Up @@ -248,6 +249,9 @@ namespace GUIUtil
private:
bool eventFilter(QObject *object, QEvent *event);
};

// Fix known bugs in QProgressDialog class.
void PolishProgressDialog(QProgressDialog* dialog);
} // namespace GUIUtil

#endif // BITCOIN_QT_GUIUTIL_H
17 changes: 6 additions & 11 deletions src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,19 @@ void WalletView::usedReceivingAddresses()

void WalletView::showProgress(const QString &title, int nProgress)
{
if (nProgress == 0)
{
progressDialog = new QProgressDialog(title, "", 0, 100);
if (nProgress == 0) {
progressDialog = new QProgressDialog(title, tr("Cancel"), 0, 100);
GUIUtil::PolishProgressDialog(progressDialog);
progressDialog->setWindowModality(Qt::ApplicationModal);
progressDialog->setMinimumDuration(0);
progressDialog->setAutoClose(false);
progressDialog->setValue(0);
progressDialog->setCancelButtonText(tr("Cancel"));
}
else if (nProgress == 100)
{
if (progressDialog)
{
} else if (nProgress == 100) {
if (progressDialog) {
progressDialog->close();
progressDialog->deleteLater();
}
}
else if (progressDialog) {
} else if (progressDialog) {
if (progressDialog->wasCanceled()) {
getWalletModel()->wallet().abortRescan();
} else {
Expand Down

0 comments on commit cd42553

Please sign in to comment.