Merge #15040: qt: Add workaround for QProgressDialog bug on macOS

7c572c488 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
This commit is contained in:
Jonas Schnelli 2019-01-17 11:16:54 -10:00
commit cd42553b11
No known key found for this signature in database
GPG key ID: 1EB776BB03C7922D
4 changed files with 32 additions and 23 deletions

View file

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

View file

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

View file

@ -31,6 +31,7 @@ class QAbstractItemView;
class QDateTime;
class QFont;
class QLineEdit;
class QProgressDialog;
class QUrl;
class QWidget;
QT_END_NAMESPACE
@ -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

View file

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