Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Problem when stacking DropAreas

    QML and Qt Quick
    2
    9
    1199
    Loading More Posts
    • 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.
    • D
      dzimiwine last edited by

      Hi,
      I have an Item with a DropArea which contains a child item with also a DropArea. When I drag something onto the child's DropArea, it is the parent's DropArea that receives drop events. Is there a way to workaround it. I am using Qt-5.5 alpha.

      Regards

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @dzimiwine last edited by

        Hi @dzimiwine
        Can you post an example which shows the problem ?

        157

        D 1 Reply Last reply Reply Quote 0
        • D
          dzimiwine @p3c0 last edited by p3c0

          @p3c0 Thanks for your reply.
          This is a small code that shows the problem:

          main.qml:

          import QtQuick 2.4
          import QtQuick.Controls 1.3
          import QtQuick.Window 2.2
          import QtQuick.Dialogs 1.2
          
          ApplicationWindow {
              title: qsTr("Hello World")
              width: 640
              height: 480
              visible: true
          
              Rectangle
              {
                  x: 40
                  y: 40
                  width: 200
                  height: 200
                  color: parentDropArea.containsDrag ? "purple" : "red"
          
                  DropArea {
                      id: parentDropArea
                      anchors.fill: parent
                  }
          
                  Rectangle {
                      x: 10
                      y: 20
                      color: childDropArea.containsDrag ? "purple" : "blue"
                      width: 100
                      height: 100
          
                      DropArea {
                          id: childDropArea
                          anchors.fill: parent
                      }
                  }
              }
          
          
              Rectangle
              {
                  id: draggableItem
                  color: "green"
                  x: 10
                  y: 10
                  width: 20
                  height: 20
                  Drag.active: mouseArea.drag.active
                  MouseArea
                  {        id: mouseArea
                      anchors.fill: parent
                      drag.target: parent
                  }
              }
          }
          
          p3c0 1 Reply Last reply Reply Quote 0
          • p3c0
            p3c0 Moderators @dzimiwine last edited by

            @dzimiwine To make the events generate properly and propagate try putting Rectangle inside DropArea as follows:

            DropArea {
                x: 40
                y: 40
                width: 200
                height: 200
            
                Rectangle {
                    anchors.fill: parent
                    color: parent.containsDrag ? "purple" : "red"
                }
            
                DropArea {
                    x: 10
                    y: 20
                    width: 100
                    height: 100
            
                    Rectangle {
                        anchors.fill: parent
                        color: parent.containsDrag ? "purple" : "blue"
                    }
                }
            }
            

            In this way you do not need to reject any events that you would need in your earlier approach.

            157

            1 Reply Last reply Reply Quote 0
            • D
              dzimiwine last edited by

              Thanks a lot. It works!! Is the problem because the child item is not a child of the parent's drop area?

              p3c0 1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators @dzimiwine last edited by

                @dzimiwine Yes I think. Or else you have to reject the events to allow them to propagate to other areas.

                157

                D 2 Replies Last reply Reply Quote 0
                • D
                  dzimiwine @p3c0 last edited by

                  @p3c0 Ok. Thanks

                  1 Reply Last reply Reply Quote 0
                  • D
                    dzimiwine @p3c0 last edited by

                    @p3c0 Btw why it is not handled like mouse areas? Mouse events are properly propagated across them.

                    p3c0 1 Reply Last reply Reply Quote 0
                    • p3c0
                      p3c0 Moderators @dzimiwine last edited by

                      @dzimiwine No. Mouse events too wont. For a test try replacing DropArea with MouseArea and containsDrag with containsMouse in your original example.

                      157

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post