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. Detect whether Item is Currently being dragged
Qt 6.11 is out! See what's new in the release blog

Detect whether Item is Currently being dragged

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 969 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by
    #1

    I have a GridView where I can drag items, following the draganddrop example:

    model: DelegateModel {
          delegate: DropArea {
              id: delegateRoot
    
              width: 80; height: 80
    
              onEntered: visualModel.items.move(drag.source.visualIndex, icon.visualIndex)
              property int visualIndex: DelegateModel.itemsIndex
              Binding { target: icon; property: "visualIndex"; value: visualIndex }
    
              Rectangle {
                  id: icon
                  property int visualIndex: 0
                  width: 72; height: 72
                  anchors {
                      horizontalCenter: parent.horizontalCenter;
                      verticalCenter: parent.verticalCenter
                  }
                  radius: 3
                  color: model.color
    
                  Text {
                      anchors.centerIn: parent
                      color: "white"
                      text: parent.visualIndex
                  }
    
                  DragHandler {
                      id: dragHandler
                  }
    
                  Drag.active: dragHandler.active
                  Drag.source: icon
                  Drag.hotSpot.x: 36
                  Drag.hotSpot.y: 36
    
                  states: [
                      State {
                          when: icon.Drag.active
                          ParentChange {
                              target: icon
                              parent: root
                          }
    
                          AnchorChanges {
                              target: icon
                              anchors.horizontalCenter: undefined
                              anchors.verticalCenter: undefined
                          }
                      }
                  ]
              }
          }
    

    How can I determine whether the item is at rest in the grid, or displaced through dragging? The reason I need this: The item gets a MouseArea where I want to assign an action to onPressAndHold. However, this action should not be triggered during dragging.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxwell31
      wrote on last edited by
      #2

      Its actually easy:
      check for icon.Drag.active

      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