QProgressDialog: make the cancel button retranslate on LanguageChange
It is documented to be, and the LanguageChange event is caught and processed. However, retranslateStrings() uses QProgressDialog::setCancelButtonText(), which unconditionally sets useDefaultCancelText=true, blocking any further changes to the button text by subsequent LanguageChange events. The fix is to use extracted QProgressDialogPrivate::setCancelButtonText() which - quite intentionally - doesn't set useDefaultCancelText. Task-number: QTBUG-40504 Change-Id: I6e701deda10c454cb088c0b0778ac2d6adff574a Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
ab79a8a76c
commit
c7386938b4
@ -179,9 +179,8 @@ void QProgressDialogPrivate::layout()
|
|||||||
|
|
||||||
void QProgressDialogPrivate::retranslateStrings()
|
void QProgressDialogPrivate::retranslateStrings()
|
||||||
{
|
{
|
||||||
Q_Q(QProgressDialog);
|
|
||||||
if (useDefaultCancelText)
|
if (useDefaultCancelText)
|
||||||
q->setCancelButtonText(QProgressDialog::tr("Cancel"));
|
setCancelButtonText(QProgressDialog::tr("Cancel"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QProgressDialogPrivate::_q_disconnectOnClose()
|
void QProgressDialogPrivate::_q_disconnectOnClose()
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
#include <qpointer.h>
|
#include <qpointer.h>
|
||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
|
#include <qtranslator.h>
|
||||||
|
|
||||||
class tst_QProgressDialog : public QObject
|
class tst_QProgressDialog : public QObject
|
||||||
{
|
{
|
||||||
@ -63,6 +64,7 @@ private Q_SLOTS:
|
|||||||
void task198202();
|
void task198202();
|
||||||
void QTBUG_31046();
|
void QTBUG_31046();
|
||||||
void settingCustomWidgets();
|
void settingCustomWidgets();
|
||||||
|
void i18n();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QProgressDialog::cleanup()
|
void tst_QProgressDialog::cleanup()
|
||||||
@ -234,5 +236,48 @@ void tst_QProgressDialog::settingCustomWidgets()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class QTestTranslator : public QTranslator
|
||||||
|
{
|
||||||
|
const QString m_str;
|
||||||
|
public:
|
||||||
|
explicit QTestTranslator(QString str) : m_str(qMove(str)) {}
|
||||||
|
|
||||||
|
QString translate(const char *, const char *sourceText, const char *, int) const Q_DECL_OVERRIDE
|
||||||
|
{ return m_str + sourceText + m_str; }
|
||||||
|
|
||||||
|
bool isEmpty() const Q_DECL_OVERRIDE { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Translator>
|
||||||
|
class QTranslatorGuard {
|
||||||
|
Translator t;
|
||||||
|
public:
|
||||||
|
template <typename Arg>
|
||||||
|
explicit QTranslatorGuard(Arg a) : t(qMove(a))
|
||||||
|
{ qApp->installTranslator(&t); }
|
||||||
|
~QTranslatorGuard()
|
||||||
|
{ qApp->removeTranslator(&t); }
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_QProgressDialog::i18n()
|
||||||
|
{
|
||||||
|
QProgressDialog dlg;
|
||||||
|
QPushButton *btn = dlg.findChild<QPushButton*>();
|
||||||
|
QVERIFY(btn);
|
||||||
|
const QString xxx = QStringLiteral("xxx");
|
||||||
|
{
|
||||||
|
QTranslatorGuard<QTestTranslator> guard(xxx);
|
||||||
|
{
|
||||||
|
QPushButton *btn = dlg.findChild<QPushButton*>();
|
||||||
|
QVERIFY(btn);
|
||||||
|
QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
|
||||||
|
QVERIFY(btn->text().startsWith(xxx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QVERIFY(btn);
|
||||||
|
QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
|
||||||
|
QVERIFY(!btn->text().startsWith(xxx));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QProgressDialog)
|
QTEST_MAIN(tst_QProgressDialog)
|
||||||
#include "tst_qprogressdialog.moc"
|
#include "tst_qprogressdialog.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user