SWT DragSourceEvent image not anchored to mouse pointer correctly

258 views Asked by At

I have the following issue when I drag and drop from a tree viewer in SWT. I am setting the image attribute of the dragSourceEvent e.g.

event.image = _dragImage 

which works fine EXCEPT for instances where I have a long label on my tree viewer node. If I have a long string and start the drag event from the far right edge of the caption on the node, I notice that the drag image is not correctly anchored and is actually offset X pixels according to the distance from the start of the tree node string to the end of the tree node string.

Anyone any suggestions? Yee would probably have to demo to get an idea of it. Has anyone seen this?

1

There are 1 answers

0
Ned Twigg On

If you set the fields event.offsetX and event.offsetY to 0, it will put the top-left of the image exactly on the mouse pointer.

If you set them to 100, it will put the top-left of the image 100 pixels to the left and above the mouse pointer.

SWT pre-populates these numbers in an attempt to get your image to line up with the offset of your original click. Not sure why it's not working in your case.