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.
Update (patch 3): Menu is removed from each of the styles from 
tst_Sanity::attachedObjects_data() (in tst_sanity.cpp file).

Fixes: QTBUG-93856
Change-Id: If95080250c3953d4293a9e1dbcc6225d21ee034f
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit d0a83e3330)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit e6478662c1)
(cherry picked from commit 933ef03332)
Reviewed-by: MohammadHossein Qanbari <mohammad.qanbari@qt.io>
This commit is contained in:
MohammadHossein Qanbari 2023-11-13 13:44:22 +01:00
parent 819a00ac50
commit 94d61bc086
8 changed files with 33 additions and 39 deletions

View File

@ -54,9 +54,7 @@ T.Menu {
contentItem: ListView {
implicitHeight: contentHeight
model: control.contentModel
interactive: Window.window
? contentHeight + control.topPadding + control.bottomPadding > Window.window.height
: false
interactive: contentHeight + control.topPadding + control.bottomPadding > control.height
clip: true
currentIndex: control.currentIndex

View File

@ -58,9 +58,7 @@ T.Menu {
contentItem: ListView {
implicitHeight: contentHeight
model: control.contentModel
interactive: Window.window
? contentHeight + control.topPadding + control.bottomPadding > Window.window.height
: false
interactive: contentHeight + control.topPadding + control.bottomPadding > control.height
clip: true
currentIndex: control.currentIndex

View File

@ -68,9 +68,7 @@ T.Menu {
contentItem: ListView {
implicitHeight: contentHeight
model: control.contentModel
interactive: Window.window
? contentHeight + control.topPadding + control.bottomPadding > Window.window.height
: false
interactive: contentHeight + control.topPadding + control.bottomPadding > control.height
clip: true
currentIndex: control.currentIndex

View File

@ -73,9 +73,7 @@ T.Menu {
implicitHeight: contentHeight
model: control.contentModel
interactive: Window.window
? contentHeight + control.topPadding + control.bottomPadding > Window.window.height
: false
interactive: contentHeight + control.topPadding + control.bottomPadding > control.height
clip: true
currentIndex: control.currentIndex

View File

@ -55,9 +55,7 @@ T.Menu {
contentItem: ListView {
implicitHeight: contentHeight
model: control.contentModel
interactive: Window.window
? contentHeight + control.topPadding + control.bottomPadding > Window.window.height
: false
interactive: contentHeight + control.topPadding + control.bottomPadding > control.height
clip: true
currentIndex: control.currentIndex

View File

@ -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)
}
}
}
}

View File

@ -1778,6 +1778,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()

View File

@ -458,11 +458,6 @@ void tst_Sanity::attachedObjects_data()
QTest::newRow("Basic/HorizontalHeaderView.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Basic/ItemDelegate.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Basic/Label.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Basic/Menu.qml") << ignoredNames << StringPairSet {
{ "QQuickOverlayAttached", "Menu_QMLTYPE" },
{ "QQuickScrollIndicatorAttached", "QQuickListView" },
{ "QQuickWindowAttached", "QQuickListView" }
};
QTest::newRow("Basic/MenuBar.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Basic/MenuBarItem.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Basic/MenuItem.qml") << ignoredNames << StringPairSet {};
@ -513,11 +508,6 @@ void tst_Sanity::attachedObjects_data()
QTest::newRow("Fusion/HorizontalHeaderView.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Fusion/ItemDelegate.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Fusion/Label.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Fusion/Menu.qml") << ignoredNames << StringPairSet {
{ "QQuickOverlayAttached", "Menu_QMLTYPE" },
{ "QQuickScrollIndicatorAttached", "QQuickListView" },
{ "QQuickWindowAttached", "QQuickListView" }
};
QTest::newRow("Fusion/MenuBar.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Fusion/MenuBarItem.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Fusion/MenuItem.qml") << ignoredNames << StringPairSet {};
@ -573,13 +563,6 @@ void tst_Sanity::attachedObjects_data()
QTest::newRow("Material/HorizontalHeaderView.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Material/ItemDelegate.qml") << ignoredNames << StringPairSet {{ "QQuickMaterialStyle", "ItemDelegate_QMLTYPE" }};
QTest::newRow("Material/Label.qml") << ignoredNames << StringPairSet {{ "QQuickMaterialStyle", "Label_QMLTYPE" }};
QTest::newRow("Material/Menu.qml") << ignoredNames << StringPairSet {
{ "QQuickOverlayAttached", "Menu_QMLTYPE" },
{ "QQuickMaterialStyle", "Menu_QMLTYPE" },
{ "QQuickScrollIndicatorAttached", "QQuickListView" },
{ "QQuickWindowAttached", "QQuickListView" },
{ "QQuickMaterialStyle", "ScrollIndicator_QMLTYPE" }
};
QTest::newRow("Material/MenuBar.qml") << ignoredNames << StringPairSet {{ "QQuickMaterialStyle", "MenuBar_QMLTYPE" }};
QTest::newRow("Material/MenuBarItem.qml") << ignoredNames << StringPairSet {{ "QQuickMaterialStyle", "MenuBarItem_QMLTYPE" }};
QTest::newRow("Material/MenuItem.qml") << ignoredNames << StringPairSet {{ "QQuickMaterialStyle", "MenuItem_QMLTYPE" }};
@ -646,13 +629,6 @@ void tst_Sanity::attachedObjects_data()
QTest::newRow("Universal/HorizontalHeaderView.qml") << ignoredNames << StringPairSet {};
QTest::newRow("Universal/ItemDelegate.qml") << ignoredNames << StringPairSet {{ "QQuickUniversalStyle", "ItemDelegate_QMLTYPE" }};
QTest::newRow("Universal/Label.qml") << ignoredNames << StringPairSet {{ "QQuickUniversalStyle", "Label_QMLTYPE" }};
QTest::newRow("Universal/Menu.qml") << ignoredNames << StringPairSet {
{ "QQuickOverlayAttached", "Menu_QMLTYPE" },
{ "QQuickUniversalStyle", "Menu_QMLTYPE" },
{ "QQuickScrollIndicatorAttached", "QQuickListView" },
{ "QQuickWindowAttached", "QQuickListView" },
{ "QQuickUniversalStyle", "ScrollIndicator_QMLTYPE" }
};
QTest::newRow("Universal/MenuBar.qml") << ignoredNames << StringPairSet {{ "QQuickUniversalStyle", "MenuBar_QMLTYPE" }};
QTest::newRow("Universal/MenuBarItem.qml") << ignoredNames << StringPairSet {{ "QQuickUniversalStyle", "MenuBarItem_QMLTYPE" }};
QTest::newRow("Universal/MenuItem.qml") << ignoredNames << StringPairSet {{ "QQuickUniversalStyle", "MenuItem_QMLTYPE" }};