[Solved] QML and Drag and Drop

Page  
3

December 29, 2010

Deqing Deqing
Lab Rat
29 posts

Cool! I solved it by simply moving “parent: loc” into the state “active”.

Thanks a lot!

January 13, 2011

kyleplattner kyleplattner
Lab Rat
242 posts

Just a followup question: How can I persist the drag and dropped location so that when the user navigates away from the page and returns the arrangement that the user chose is still present.

January 19, 2011

Deqing Deqing
Lab Rat
29 posts

I guess you need to store the locations in the model.

January 19, 2011

kyleplattner kyleplattner
Lab Rat
242 posts

I do need to keep the locations of the dragged items. What would be the best way to accomplish this?

January 21, 2011

Deqing Deqing
Lab Rat
29 posts

I’m using C++ data model and store items in a list.

When drag-and-drop finishes, I will not only move items in the GridView, but also move them inside the list in C++ code at the same time.

June 10, 2011

sfjam sfjam
Lab Rat
41 posts

this can work in one screen,but when i scroll the screen,this does not work,how to change it

July 27, 2011

xsacha xsacha
Lab Rat
517 posts

Hi sfjam. Can you elaborate on your issue?

Are you scrolling to a second GridView or scrolling within the GridView?

My solution for scrolling within a GridView is on the previous page (fourth comment from bottom).

If you want multiple GridViews, the code gets more complex. Post back if this is what you desire (multi-grid draggable icon layout).

 Signature 

- Sacha

October 13, 2011

fonzi337 fonzi337
Lab Rat
41 posts

Wow, thanks xsacha for putting this together! It’s amazing how little code is involved to get such nice complex-looking behavior. :)

I suggest a small tweak to the code: it looks like if an item at a lower index is in the active state and is moved towards an item of a higher index in the model, the active item is drawn behind the item with the higher model index. Setting the z value of the active item in the state PropertyChanges definition should do the trick:

  1. PropertyChanges { target: item; x: loc.mouseX - width/2; y: loc.mouseY - height/2; scale: 0.5; z: 500 }

October 14, 2011

xsacha xsacha
Lab Rat
517 posts

Thanks, I’ll add that :)

 Signature 

- Sacha

August 29, 2012

meolic meolic
Lab Rat
5 posts

If I change line 23 in Main.qml to have “onPressed” instead of “onPressAndHold”, the application is not working properly (problem with index). Where is the problem and how to solve it?

EDIT: Adding hoverEnabled: true solved this issue. But I’m not sure whether hoverEnabled has important impact on efficiency?

August 29, 2012

meolic meolic
Lab Rat
5 posts
Deqing wrote:
Cool! I solved it by simply moving “parent: loc” into the state “active”.

I am trying the same. But items are not correctly drawn (wrong x,y) if I remove “parent: loc” from Image {id: item … }.

Can you give us your solution, please.

Page  
3

  ‹‹ QML Simulator      Setting focus. Differences between focus and activeFocus properties. Help for the pratcial example ››

You must log in to post a reply. Not a member yet? Register here!