aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickdialogbuttonbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickdialogbuttonbox.cpp')
-rw-r--r--src/quicktemplates2/qquickdialogbuttonbox.cpp51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp
index 91fb41f2..f3dd2da1 100644
--- a/src/quicktemplates2/qquickdialogbuttonbox.cpp
+++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
/*!
\qmltype DialogButtonBox
\inherits Container
- \instantiates QQuickDialogButtonBox
+//! \instantiates QQuickDialogButtonBox
\inqmlmodule QtQuick.Controls
\ingroup qtquickcontrols2-dialogs
\brief A button box used in dialogs.
@@ -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,27 @@ 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;
+ // The button might be a custom one with explicitly specified text, so we shouldn't change it in that case.
+ if (standardButton != QPlatformDialogHelper::NoButton) {
+ const QString buttonText = QGuiApplicationPrivate::platformTheme()->standardButtonText(standardButton);
+ button->setText(QPlatformTheme::removeMnemonics(buttonText));
+ }
+ }
+ --i;
+ }
+}
+
QQuickDialogButtonBox::QQuickDialogButtonBox(QQuickItem *parent)
: QQuickContainer(*(new QQuickDialogButtonBoxPrivate), parent)
{
@@ -523,7 +545,7 @@ void QQuickDialogButtonBox::setAlignment(Qt::Alignment alignment)
void QQuickDialogButtonBox::resetAlignment()
{
- setAlignment(0);
+ setAlignment({});
}
/*!
@@ -684,11 +706,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)