aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickdialogbuttonbox.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-09-09 15:59:49 +0200
committerMitch Curtis <mitch.curtis@qt.io>2019-09-11 14:02:15 +0200
commitc18c7bd7f9596e5ad3d13876a91203e1ceba2544 (patch)
tree76eea6eb3c24ae4aab5ac22925b2e71caa46c05c /src/quicktemplates2/qquickdialogbuttonbox.cpp
parent1fec97053884d998442710a5d4258ffb6bed8955 (diff)
DialogButtonBox: fix standard buttons not being translated
When calling QQmlEngine::retranslate() after component completion, buttons in a DialogButtonBox were not being retranslated. For now the only way to be notified of language change events is by installing an event filter on the application, but in the future we can use the solution to QTBUG-78141 instead. Change-Id: Ibc435c3829945489adcbaa8a813013fe735a9c38 Fixes: QTBUG-75085 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickdialogbuttonbox.cpp')
-rw-r--r--src/quicktemplates2/qquickdialogbuttonbox.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp
index 91fb41f2..10d80778 100644
--- a/src/quicktemplates2/qquickdialogbuttonbox.cpp
+++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp
@@ -430,7 +430,8 @@ void QQuickDialogButtonBoxPrivate::removeStandardButtons()
while (i >= 0) {
QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(q->itemAt(i));
if (button) {
- QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>(qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, false));
+ QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>(
+ qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, false));
if (attached) {
QQuickDialogButtonBoxAttachedPrivate *p = QQuickDialogButtonBoxAttachedPrivate::get(attached);
if (p->standardButton != QPlatformDialogHelper::NoButton) {
@@ -443,6 +444,24 @@ void QQuickDialogButtonBoxPrivate::removeStandardButtons()
}
}
+void QQuickDialogButtonBoxPrivate::updateLanguage()
+{
+ Q_Q(QQuickDialogButtonBox);
+ int i = q->count() - 1;
+ while (i >= 0) {
+ QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(itemAt(i));
+ if (button) {
+ QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>(
+ qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, true));
+ const auto boxAttachedPrivate = QQuickDialogButtonBoxAttachedPrivate::get(attached);
+ const QPlatformDialogHelper::StandardButton standardButton = boxAttachedPrivate->standardButton;
+ const QString buttonText = QGuiApplicationPrivate::platformTheme()->standardButtonText(standardButton);
+ button->setText(QPlatformTheme::removeMnemonics(buttonText));
+ }
+ --i;
+ }
+}
+
QQuickDialogButtonBox::QQuickDialogButtonBox(QQuickItem *parent)
: QQuickContainer(*(new QQuickDialogButtonBoxPrivate), parent)
{
@@ -684,11 +703,34 @@ void QQuickDialogButtonBox::updatePolish()
d->updateLayout();
}
+class LanguageEventFilter : public QObject
+{
+public:
+ LanguageEventFilter(QQuickDialogButtonBoxPrivate *box)
+ : QObject(box->q_ptr)
+ , boxPrivate(box)
+ {
+ }
+
+protected:
+ bool eventFilter(QObject *, QEvent *event)
+ {
+ if (event->type() == QEvent::LanguageChange)
+ boxPrivate->updateLanguage();
+ return false;
+ }
+
+private:
+ QQuickDialogButtonBoxPrivate *boxPrivate;
+};
+
void QQuickDialogButtonBox::componentComplete()
{
Q_D(QQuickDialogButtonBox);
QQuickContainer::componentComplete();
d->updateLayout();
+ // TODO: use the solution in QTBUG-78141 instead, when it's implemented.
+ qApp->installEventFilter(new LanguageEventFilter(d));
}
void QQuickDialogButtonBox::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)