diff options
-rw-r--r-- | src/corelib/global/qnamespace.qdoc | 4 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 2 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 28 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 71cd9444d6..59fa0b519c 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -1151,8 +1151,8 @@ and Windows) the window will take a modified appearance. This flag is set or cleared by QWidget::setWindowModified(). - \value WA_WindowPropagation Makes a toplevel window inherit font and - palette from its parent. + \value WA_WindowPropagation Makes a toplevel window inherit font, palette + and locale from its parent. \value WA_MacAlwaysShowToolWindow On \macos, show the tool window even when the application is not active. By default, all tool windows are diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index cf90df6b9b..7e9e4f0a98 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5993,7 +5993,7 @@ void QWidgetPrivate::resolveLocale() Q_Q(const QWidget); if (!q->testAttribute(Qt::WA_SetLocale)) { - setLocale_helper(q->isWindow() + setLocale_helper(q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation) ? QLocale() : q->parentWidget()->locale()); } diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 731a8c5d91..2698777ac8 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -277,6 +277,7 @@ private slots: #endif void setLocale(); + void propagateLocale(); void deleteStyle(); void multipleToplevelFocusCheck(); void setFocus(); @@ -1203,6 +1204,33 @@ void tst_QWidget::setLocale() QCOMPARE(child2.locale(), QLocale(QLocale::French)); } +void tst_QWidget::propagateLocale() +{ + QWidget parent; + parent.setLocale(QLocale::French); + // Non-window widget; propagates locale: + QWidget *child = new QWidget(&parent); + QVERIFY(!child->isWindow()); + QVERIFY(!child->testAttribute(Qt::WA_WindowPropagation)); + QCOMPARE(child->locale(), QLocale(QLocale::French)); + parent.setLocale(QLocale::Italian); + QCOMPARE(child->locale(), QLocale(QLocale::Italian)); + delete child; + // Window: doesn't propagate locale: + child = new QWidget(&parent, Qt::Window); + QVERIFY(child->isWindow()); + QVERIFY(!child->testAttribute(Qt::WA_WindowPropagation)); + QCOMPARE(child->locale(), QLocale()); + parent.setLocale(QLocale::French); + QCOMPARE(child->locale(), QLocale()); + // ... unless we tell it to: + child->setAttribute(Qt::WA_WindowPropagation, true); + QVERIFY(child->testAttribute(Qt::WA_WindowPropagation)); + QCOMPARE(child->locale(), QLocale(QLocale::French)); + parent.setLocale(QLocale::Italian); + QCOMPARE(child->locale(), QLocale(QLocale::Italian)); +} + void tst_QWidget::visible_setWindowOpacity() { QScopedPointer<QWidget> testWidget(new QWidget); |