Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MouseArea blocks 'Custom Scene Graph Item's mouse events
Forum Updated to NodeBB v4.3 + New Features

MouseArea blocks 'Custom Scene Graph Item's mouse events

Scheduled Pinned Locked Moved Unsolved General and Desktop
qquickitemscene graphqtquickmousearea
2 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kafanti
    wrote on 22 Feb 2016, 10:11 last edited by
    #1

    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.

    S 1 Reply Last reply 26 May 2016, 12:09
    0
    • K kafanti
      22 Feb 2016, 10:11

      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.

      S Offline
      S Offline
      skol
      wrote on 26 May 2016, 12:09 last edited by skol
      #2

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

      You need:

      onPressed: {
      mouse.accepted = false;
      }

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved