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. event dispatch of QQuickItem

event dispatch of QQuickItem

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 1.6k 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.
  • A Offline
    A Offline
    amyhaber
    wrote on last edited by amyhaber
    #1

    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 hierarchy

    I 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
        }
    }
    
    jsulmJ 1 Reply Last reply
    0
    • A amyhaber

      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 hierarchy

      I 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
          }
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      A 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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

        A Offline
        A Offline
        amyhaber
        wrote on last edited by
        #3

        @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

        jsulmJ 1 Reply Last reply
        0
        • A amyhaber

          @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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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?

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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?

            A Offline
            A Offline
            amyhaber
            wrote on last edited by
            #5

            @jsulm yeah, actually I know how to handle event, “the next item” means the next item of z-order.

            jsulmJ A 2 Replies Last reply
            0
            • A amyhaber

              @jsulm yeah, actually I know how to handle event, “the next item” means the next item of z-order.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6
              This post is deleted!
              A 1 Reply Last reply
              0
              • jsulmJ jsulm

                This post is deleted!

                A Offline
                A Offline
                amyhaber
                wrote on last edited by
                #7

                @jsulm

                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

                1 Reply Last reply
                0
                • A amyhaber

                  @jsulm yeah, actually I know how to handle event, “the next item” means the next item of z-order.

                  A Offline
                  A Offline
                  amyhaber
                  wrote on last edited by amyhaber
                  #8

                  @jsulm and thanks for your patient, I think I can declare a property in my control. when QML code instantiate this control, it must tell the control which item is the "next item of z-order" by assigning a value to this property

                  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