event dispatch of QQuickItem
-
Hi, buddies
I use QQuickPaintedItem as base class to develop a new control, this control should only accept mouse event.
my question is:
how can I process an event and then deliver it to the next item in the item hierarchyI think QCoreApplication::sendEvent(QObject *receiver, QEvent *event) should achieve the goal, but the problem is, is
there any way to get the next item (the receiver parameter of QCoreApplication::sendEvent) by Z-Order ??class MaskItem : public QQuickPaintedItem { Q_OBJECT private: void paint(QPainter *painter) override { //... } bool event(QEvent* e) override { //... } };
ApplicationWindow{ width: 800 height: 600 minimumWidth: 400 minimumHeight: 300 visible: true Rectangle{ anchors.fill: parent color: "SkyBlue" MouseArea{ id: realItem anchors.fill: parent acceptedButtons: Qt.AllButtons onPressed: { console.log("pressed:", mouse.button) } onClicked: { console.log("clicked:", mouse.button) } } } background: MaskItem{ anchors.fill: parent z: 999 } }
-
Hi, buddies
I use QQuickPaintedItem as base class to develop a new control, this control should only accept mouse event.
my question is:
how can I process an event and then deliver it to the next item in the item hierarchyI think QCoreApplication::sendEvent(QObject *receiver, QEvent *event) should achieve the goal, but the problem is, is
there any way to get the next item (the receiver parameter of QCoreApplication::sendEvent) by Z-Order ??class MaskItem : public QQuickPaintedItem { Q_OBJECT private: void paint(QPainter *painter) override { //... } bool event(QEvent* e) override { //... } };
ApplicationWindow{ width: 800 height: 600 minimumWidth: 400 minimumHeight: 300 visible: true Rectangle{ anchors.fill: parent color: "SkyBlue" MouseArea{ id: realItem anchors.fill: parent acceptedButtons: Qt.AllButtons onPressed: { console.log("pressed:", mouse.button) } onClicked: { console.log("clicked:", mouse.button) } } } background: MaskItem{ anchors.fill: parent z: 999 } }
@amyhaber Actually it should be enough to only override what you need and ignore everything else.
For example you can override mousePressEvent(...).
See http://doc.qt.io/qt-5.9/eventsandfilters.html -
@amyhaber Actually it should be enough to only override what you need and ignore everything else.
For example you can override mousePressEvent(...).
See http://doc.qt.io/qt-5.9/eventsandfilters.html -
@jsulm I didn't make myself clear, for example. the MarskItem got right button click event, I wanna handle it and then deliver the event to next item.
BTW: thanks for your reply , I'll edit my question
-
@amyhaber To handle right click override mousePressEvent(...) and read the link I posted.
"and then deliver the event to next item" - what exactly does this mean? What is "next item"? Do you mean parent? -
@jsulm yeah, actually I know how to handle event, “the next item” means the next item of z-order.
This post is deleted! -
ApplicationWindow{ width: 800 height: 600 minimumWidth: 400 minimumHeight: 300 visible: true Rectangle{ anchors.fill: parent color: "SkyBlue" MouseArea{ id: itemContent anchors.fill: parent acceptedButtons: Qt.AllButtons onPressed: { console.log("pressed:", mouse.button) } onClicked: { console.log("clicked:", mouse.button) } } } background: MaskItem{ id: itemMask anchors.fill: parent z: 999 } }
here is the sample code, itemMask and itemContent have same position & size in ApplicationWindow. the only difference is z value.
so now I wanna itemMask can draw something according to the received event. but sometime it also need deliver the event to itemContent
for example, when itemMask received right button clicked, I wanna itemContent can also perceive the click event -
@jsulm yeah, actually I know how to handle event, “the next item” means the next item of z-order.