From 933ef033321e5113dd1beaddfd883b40f3658bab Mon Sep 17 00:00:00 2001 From: MohammadHossein Qanbari Date: Mon, 13 Nov 2023 13:44:22 +0100 Subject: [PATCH] Menu: fix contentItem's interactive The interactive property of the Menu's contentItem depends on its Menu (control) when Window.window is valid. In the case of a fixed-height menu, even if the contentItem's height is smaller than Window.window.height, the interactive property of the contentItem would be false if the menu's height is smaller than the window's height and also smaller than its contentItem's height. Fixes: QTBUG-93856 Pick-to: 6.2 Change-Id: If95080250c3953d4293a9e1dbcc6225d21ee034f Reviewed-by: Mitch Curtis (cherry picked from commit d0a83e33305f0ab11751627446b2084bdc85de68) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit e6478662c1f2dfe47023bdf35ebf344c60d1b3d4) --- src/quickcontrols/basic/Menu.qml | 4 +-- src/quickcontrols/fusion/Menu.qml | 4 +-- src/quickcontrols/imagine/Menu.qml | 4 +-- src/quickcontrols/ios/Menu.qml | 4 +-- src/quickcontrols/material/Menu.qml | 4 +-- src/quickcontrols/universal/Menu.qml | 4 +-- .../data/scrollableWithFixedHeight.qml | 27 +++++++++++++++++++ .../qquickmenu/tst_qquickmenu.cpp | 1 + 8 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 tests/auto/quickcontrols/qquickmenu/data/scrollableWithFixedHeight.qml diff --git a/src/quickcontrols/basic/Menu.qml b/src/quickcontrols/basic/Menu.qml index 288a618de0..f18b40545f 100644 --- a/src/quickcontrols/basic/Menu.qml +++ b/src/quickcontrols/basic/Menu.qml @@ -22,8 +22,8 @@ T.Menu { implicitHeight: contentHeight model: control.contentModel interactive: Window.window - ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height - : false + ? contentHeight + control.topPadding + control.bottomPadding > control.height + : false clip: true currentIndex: control.currentIndex diff --git a/src/quickcontrols/fusion/Menu.qml b/src/quickcontrols/fusion/Menu.qml index b35ad7d97c..96a76f6c60 100644 --- a/src/quickcontrols/fusion/Menu.qml +++ b/src/quickcontrols/fusion/Menu.qml @@ -26,8 +26,8 @@ T.Menu { implicitHeight: contentHeight model: control.contentModel interactive: Window.window - ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height - : false + ? contentHeight + control.topPadding + control.bottomPadding > control.height + : false clip: true currentIndex: control.currentIndex diff --git a/src/quickcontrols/imagine/Menu.qml b/src/quickcontrols/imagine/Menu.qml index da8011af0c..8a9e288d3b 100644 --- a/src/quickcontrols/imagine/Menu.qml +++ b/src/quickcontrols/imagine/Menu.qml @@ -36,8 +36,8 @@ T.Menu { implicitHeight: contentHeight model: control.contentModel interactive: Window.window - ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height - : false + ? contentHeight + control.topPadding + control.bottomPadding > control.height + : false clip: true currentIndex: control.currentIndex diff --git a/src/quickcontrols/ios/Menu.qml b/src/quickcontrols/ios/Menu.qml index eaf71751cc..0b6fee9a7c 100644 --- a/src/quickcontrols/ios/Menu.qml +++ b/src/quickcontrols/ios/Menu.qml @@ -35,8 +35,8 @@ T.Menu { implicitHeight: contentHeight model: control.contentModel interactive: Window.window - ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height - : false + ? contentHeight + control.topPadding + control.bottomPadding > control.height + : false clip: true currentIndex: control.currentIndex diff --git a/src/quickcontrols/material/Menu.qml b/src/quickcontrols/material/Menu.qml index ed92c09057..155220b1c1 100644 --- a/src/quickcontrols/material/Menu.qml +++ b/src/quickcontrols/material/Menu.qml @@ -42,8 +42,8 @@ T.Menu { model: control.contentModel interactive: Window.window - ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height - : false + ? contentHeight + control.topPadding + control.bottomPadding > control.height + : false clip: true currentIndex: control.currentIndex diff --git a/src/quickcontrols/universal/Menu.qml b/src/quickcontrols/universal/Menu.qml index 75ba9ad2da..f36a82a512 100644 --- a/src/quickcontrols/universal/Menu.qml +++ b/src/quickcontrols/universal/Menu.qml @@ -23,8 +23,8 @@ T.Menu { implicitHeight: contentHeight model: control.contentModel interactive: Window.window - ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height - : false + ? contentHeight + control.topPadding + control.bottomPadding > control.height + : false clip: true currentIndex: control.currentIndex diff --git a/tests/auto/quickcontrols/qquickmenu/data/scrollableWithFixedHeight.qml b/tests/auto/quickcontrols/qquickmenu/data/scrollableWithFixedHeight.qml new file mode 100644 index 0000000000..1156d30aef --- /dev/null +++ b/tests/auto/quickcontrols/qquickmenu/data/scrollableWithFixedHeight.qml @@ -0,0 +1,27 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Controls +import QtQuick.Window + +Window { + width: 300 + height: 300 + + property alias menu: menu + + Menu { + id: menu + anchors.centerIn: parent + height: 100 + visible: true + Repeater { + model: 10 + delegate: MenuItem { + objectName: text + text: (index + 1) + } + } + } +} diff --git a/tests/auto/quickcontrols/qquickmenu/tst_qquickmenu.cpp b/tests/auto/quickcontrols/qquickmenu/tst_qquickmenu.cpp index 503485741b..fbb4e7d5f9 100644 --- a/tests/auto/quickcontrols/qquickmenu/tst_qquickmenu.cpp +++ b/tests/auto/quickcontrols/qquickmenu/tst_qquickmenu.cpp @@ -1788,6 +1788,7 @@ void tst_QQuickMenu::scrollable_data() QTest::addRow("Window") << QString::fromLatin1("windowScrollable.qml"); QTest::addRow("ApplicationWindow") << QString::fromLatin1("applicationWindowScrollable.qml"); QTest::addRow("WithPadding") << QString::fromLatin1("scrollableWithPadding.qml"); + QTest::addRow("FixedHeight") << QString::fromLatin1("scrollableWithFixedHeight.qml"); } void tst_QQuickMenu::scrollable()