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. Reject a Drag in a DragArea

Reject a Drag in a DragArea

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 495 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.
  • lawrence.emkeL Offline
    lawrence.emkeL Offline
    lawrence.emke
    wrote on last edited by
    #1

    I have been trying to learn about Drag and Drop facilities.
    I started with the given example with the red and green Rectangle
    in which the visible property of the green rectangle is made visible
    when the red box enters it drop area.

    I noticed that I could drop the red box in any area of the window, not just
    in the dropArea! Now to learn more I would like to know how to reject
    a "drop". And to have a drop rejected for any area other than the dropArea.
    What I would like to see is that the dropped red box return to its original
    position if the drop is reject. Is this possible.

    I found some code on StackOverflow but it must be too old and causes
    an error when I try to use it.

    ODБOïO 1 Reply Last reply
    0
    • lawrence.emkeL lawrence.emke

      I have been trying to learn about Drag and Drop facilities.
      I started with the given example with the red and green Rectangle
      in which the visible property of the green rectangle is made visible
      when the red box enters it drop area.

      I noticed that I could drop the red box in any area of the window, not just
      in the dropArea! Now to learn more I would like to know how to reject
      a "drop". And to have a drop rejected for any area other than the dropArea.
      What I would like to see is that the dropped red box return to its original
      position if the drop is reject. Is this possible.

      I found some code on StackOverflow but it must be too old and causes
      an error when I try to use it.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @lawrence-emke hi
      please see the Qt Quick Examples - Drag and Drop

      1 Reply Last reply
      0
      • lawrence.emkeL Offline
        lawrence.emkeL Offline
        lawrence.emke
        wrote on last edited by
        #3
        This post is deleted!
        ODБOïO 1 Reply Last reply
        0
        • lawrence.emkeL lawrence.emke

          This post is deleted!

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          @lawrence-emke
          i did simplified version of that example,

          ApplicationWindow{
          
              width: 500
              height: 500
              visible: true
          
              Item {
                  id: root
                  width: 64; height: 64
                  MouseArea {
                      id: mouseArea
                      anchors.fill: parent
                      drag.target: tile
                      onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root
                      Rectangle {
                          id: tile
                          width: 64; height: 64
                          anchors.verticalCenter: parent.verticalCenter
                          anchors.horizontalCenter: parent.horizontalCenter
                          color: "red"
                          Drag.active: mouseArea.drag.active
                          states: State {
                              when: mouseArea.drag.active
                              ParentChange { target: tile; parent: root }
                              AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
                          }
                      }
                  }
              }
          
          
              DropArea {
                  id: dragTarget
                  width: 64; height: 64
                  anchors.centerIn: parent
                  Rectangle {
                      id: dropRectangle
                      color: "transparent"
                      anchors.fill: parent
                      border.width: 2
                      border.color: dragTarget.containsDrag ? "grey" : "black"
                  }
              }
          
          }
          
          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