Fix propagation of QContextMenuEvent for QQuickItems

QQuickDeliveryAgentPrivate::deliverContextMenuEvent() relies on that the
QContextMenuEvent gets ignored if the target item doesn't handle it,
therefore we have to make sure it is ignored by default.

This fixes the context menu for the SideBar (still WIP) and likewise the
autotest in this change.

Pick-to: 6.9
Change-Id: If72a814adc92aea6e5e071eb49cbe84b025768fb
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Jan Arve Sæther 2024-12-23 12:41:00 +01:00
parent a89a34463b
commit 04d75342dd
3 changed files with 42 additions and 0 deletions

View File

@ -9184,6 +9184,8 @@ bool QQuickItem::event(QEvent *ev)
break;
case QEvent::ContextMenu:
// ### Qt 7: add virtual contextMenuEvent (and to QWindow?)
ev->ignore();
break;
default:
return QObject::event(ev);
}

View File

@ -0,0 +1,39 @@
import QtQuick
import QtQuick.Controls
ApplicationWindow {
width: 600
height: 400
//visible: true // for manual testing
Rectangle {
objectName: "tomato"
x: 100
y: 100
width: 100
height: 100
color: "tomato"
radius: width / 2
ContextMenu.menu: Menu {
id: contextMenu
MenuItem {
text: qsTr("Eat tomato")
}
MenuItem {
text: qsTr("Throw tomato")
}
MenuItem {
text: qsTr("Squash tomato")
}
}
Rectangle {
objectName: "orange"
anchors.centerIn: parent
width: 80
height: 80
color: "orange"
radius: width / 2
}
}
}

View File

@ -47,6 +47,7 @@ void tst_QQuickContextMenu::customContextMenu_data()
QTest::addRow("Rectangle") << "customContextMenuOnRectangle.qml";
QTest::addRow("Control") << "customContextMenuOnControl.qml";
QTest::addRow("NestedRectangle") << "customContextMenuOnNestedRectangle.qml";
}
void tst_QQuickContextMenu::customContextMenu()