MouseArea blocks 'Custom Scene Graph Item's mouse events



  • Hello,

    I am implementing a custom scene graph item, which inherits QQuickItem.

    class CustomItem : public QQuickItem {
        Q_OBJECT
    public:
        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.

    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 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 , QQuickItem::mousePressEvent or QQuickItem::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 which have not been replied.



  • @kafanti
    If MouseArea handles mouse event it doesn't pass event to its parent.

    You need:

    onPressed: {
    mouse.accepted = false;
    }



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.