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. MultiPointTouchArea - Drag and Drop
Forum Updated to NodeBB v4.3 + New Features

MultiPointTouchArea - Drag and Drop

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

    I am writing a multi-touch application and I want to be able to drag multiple targets simultaneously, so I cannot use the standard MouseArea. So far, this approach works for me:

    import QtQuick 2.5
    import QtQuick.Window 2.1
    
    Window {
    	id: window
    	visible: true
    	width: 1280; height: 960
    	
    	Item {
    		id: root
    		anchors.fill: parent
    		
    		Repeater {
    			model: 4
    			
    			Repeater {
    				property var j: modelData
    				
    				model: 4
    				
    				Rectangle {
    					property var i: modelData
    					
    					x: parent.width*i/4; y: parent.height*j/4
    					width: 64; height: 64
    					color: Qt.rgba(i/4, j/4, 0, 1)
    					
    					MultiPointTouchArea {
    						property var drag: parent
    						property var offset: null
    						
    						anchors.fill: parent
    						enabled: true
    
    						minimumTouchPoints: 1
    						maximumTouchPoints: 1
    						
    						function dragMove(holder, point) {
    							if (point && drag) {
    								var position = holder.mapFromItem(drag, point.x, point.y);
    								drag.x = position.x - offset.x;
    								drag.y = position.y - offset.y;
    							}
    						}
    						
    						onPressed: {
    							var point = touchPoints[0];
    							offset = Qt.point(point.x, point.y);
    							dragMove(root, point);
    						}
    						
    						onTouchUpdated: {
    							var point = touchPoints[0];
    							dragMove(root, point);
    						}
    						
    						onReleased: {
    							var point = touchPoints[0];
    							dragMove(root, point);
    						}
    					}
    				}
    			}
    		}
    	}
    }
    

    However, this works well for moving things around, but I am stuck making it work with the Qt's Drag and Drop mechanism. Is there any way to make this work with DropArea (i.e. make it emit the entered/exited/dropped events)?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kloffy
      wrote on last edited by
      #2

      Actually, calling Drag.start, Drag.drop, and Drag.cancel appears to make it work. I was scratching my head over this but it turns out I had an event filter interfering...

      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