[Interest] MouseArea blocks 'Custom Scene Graph Item's mouse events
Sina Dogru
sinadooru at gmail.com
Mon Feb 22 13:14:41 CET 2016
Hello,
I am implementing a custom scene graph item, which inherits QQuickItem
<http://doc.qt.io/qt-5/qquickitem.html>.
class CustomItem : public QQuickItem {
Q_OBJECTpublic:
CustomItem()
{
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton);
setFlag(ItemHasContents);
}protected:
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
void hoverEnterEvent(QHoverEvent *e) override;
void hoverLeaveEvent(QHoverEvent *e) override;
void hoverMoveEvent(QHoverEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
};
And I use that CustomItem as a visual parent to some QML Types, like
Rectangle <http://doc.qt.io/qt-5/qml-qtquick-rectangle.html>.
CustomItem {
id: custom
width: 400; height: 400
Rectangle {
id: rect
z: -1
anchors.fill: parent
color: "blue"
}
}
Everything was perfect, I was able to draw over the visual childrens using
'z' property with overriding QQuickItem::updatePaintNode.
But the problem raised when I use MouseArea
<http://doc.qt.io/qt-5/qml-qtquick-mousearea.html> as a children of my
'CustomItem'.
CustomItem {
id: custom
width: 400; height: 400
Rectangle {
id: rect
z: -1
anchors.fill: parent
color: "blue"
}
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
drag.target: parent
drag.axis: Drag.XandYAxis
}
}
After that, my 'CustomItem' was not getting the mouse events like
QQuickItem::hoverEnterEvent
<http://doc.qt.io/qt-5/qquickitem.html#hoverEnterEvent> ,
QQuickItem::mousePressEvent
<https://forum.qt.io/topic/64437/doc.qt.io/qt-5/qquickitem.html#mousePressEvent>
or QQuickItem::mouseMoveEvent
<http://doc.qt.io/qt-5/qquickitem.html#mouseMoveEvent> which those are
crucial to implement in my case.
I am not sure if this even possible or am I doing something wrong? If there
is a candidate solution for that particular problem, I would be happy to
try it.
Note: Here is a similar question on StackOverFlow
<http://stackoverflow.com/questions/23986201/mouse-events-not-handled-within-qquickitem-inheritor>
which have not been replied.
I have already asked it question on QtForums
<https://forum.qt.io/topic/64437/mousearea-blocks-custom-scene-graph-item-s-mouse-events>
.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160222/84510a3d/attachment.html>
More information about the Interest
mailing list