Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem when stacking DropAreas
Forum Updated to NodeBB v4.3 + New Features

Problem when stacking DropAreas

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 1.7k Views 2 Watching
  • 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 Offline
    D Offline
    dzimiwine
    wrote on last edited by
    #1

    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

    p3c0P 1 Reply Last reply
    0
    • D dzimiwine

      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

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

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

      157

      D 1 Reply Last reply
      0
      • p3c0P p3c0

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

        D Offline
        D Offline
        dzimiwine
        wrote on last edited by p3c0
        #3

        @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
                }
            }
        }
        
        p3c0P 1 Reply Last reply
        0
        • D dzimiwine

          @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
                  }
              }
          }
          
          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @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
          0
          • D Offline
            D Offline
            dzimiwine
            wrote on last edited by
            #5

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

            p3c0P 1 Reply Last reply
            0
            • D dzimiwine

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

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @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
              0
              • p3c0P p3c0

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

                D Offline
                D Offline
                dzimiwine
                wrote on last edited by
                #7

                @p3c0 Ok. Thanks

                1 Reply Last reply
                0
                • p3c0P p3c0

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

                  D Offline
                  D Offline
                  dzimiwine
                  wrote on last edited by
                  #8

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

                  p3c0P 1 Reply Last reply
                  0
                  • D dzimiwine

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

                    p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #9

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

                    • Login

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