aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qquickmenubar/tst_qquickmenubar.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-08-16 10:36:19 +0200
committerMitch Curtis <mitch.curtis@qt.io>2018-10-02 09:04:56 +0000
commitd923dd467c1aeb3e195a09949b04862084002f88 (patch)
tree3d2ad3ab4d4989009195094bebd39276912dc5e1 /tests/auto/qquickmenubar/tst_qquickmenubar.cpp
parente7213c0460788f49ec6c2204bfd5c0517699aa51 (diff)
MenuBar: ensure the correct delegates are used when created via Component
Don't add items until we're complete, as the delegate could change in the meantime. Instead, add them to contentData and create them when we're complete. A similar fix was already done for Menu in d5cb26bc. Task-number: QTBUG-67559 Change-Id: Idb43b7a69fcf1c1ad6396c73a3c090b92e460ab8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/qquickmenubar/tst_qquickmenubar.cpp')
-rw-r--r--tests/auto/qquickmenubar/tst_qquickmenubar.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qquickmenubar/tst_qquickmenubar.cpp b/tests/auto/qquickmenubar/tst_qquickmenubar.cpp
index 754e915b..1d5844ee 100644
--- a/tests/auto/qquickmenubar/tst_qquickmenubar.cpp
+++ b/tests/auto/qquickmenubar/tst_qquickmenubar.cpp
@@ -62,6 +62,7 @@ private slots:
void keys();
void mnemonics();
void addRemove();
+ void delegateFromSeparateComponent();
};
void tst_qquickmenubar::delegate()
@@ -570,6 +571,32 @@ void tst_qquickmenubar::addRemove()
QVERIFY(menuBarItem1.isNull());
}
+// QTBUG-67559
+// Test that Menus declared as children of a MenuBar have the
+// correct delegate when it is declared outside of the MenuBar as a Component.
+void tst_qquickmenubar::delegateFromSeparateComponent()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("delegateFromSeparateComponent.qml"));
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ const QColor green = QColor::fromRgb(0x00ff00);
+
+ QQuickMenuBar *menuBar = window->property("menuBar").value<QQuickMenuBar*>();
+ QVERIFY(menuBar);
+
+ QQuickMenu *menu = qobject_cast<QQuickMenu*>(menuBar->menuAt(0));
+ QVERIFY(menu);
+
+ QQuickMenuBarItem *menuBarItem = qobject_cast<QQuickMenuBarItem *>(menu->parentItem());
+ QVERIFY(menuBarItem);
+
+ QQuickItem *menuBarItemBg = menuBarItem->property("background").value<QQuickItem*>();
+ QVERIFY(menuBarItemBg);
+ QCOMPARE(menuBarItemBg->property("color").value<QColor>(), green);
+}
+
QTEST_QUICKCONTROLS_MAIN(tst_qquickmenubar)
#include "tst_qquickmenubar.moc"