You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, September 7th 2006, 5:31pm

how to drag and drop in a grid

hey guys, i need to be able to drag and drop in a grid environment, similarly to the way the drag and drop is handled when we drag a widget onto a MainWindow in Qt designer, it lands on a grid-type background....i need to be able to do that, i currently using Qt4 and i'm using Qframe as the dropsite...will someone help me please.....

2

Thursday, September 7th 2006, 5:40pm

Ive done this in vb before. If you get your drag code to work, this is how u get it to snap to a grid size - if i remmeber correctly: (this works for both vertical and horizontal)

(psuedocode)

offset = currentdropx mod gridsizex
previouscolumn = currentdropx - offset
if (offset <= (gridsizex / 2))
setx(previouscolumn)
else
setx(previouscolumn + gridsizex)


Dont hold that to 100% working it may need some tweaks.

3

Thursday, September 7th 2006, 7:41pm

ok thanks alot but i dont understand the algorithm, is it possible for u to explain it to me? thanks in advnace

4

Thursday, September 7th 2006, 8:08pm

offset = currentdropx mod gridsizex // get the offset - the amount away from the last grid line where it was dropped
previouscolumn = currentdropx - offset // get the x value of the last grid line
if (offset <= (gridsizex / 2)) // if the drop placement was less than half of the width of the grid, put it to the left.
setx(previouscolumn)
else
setx(previouscolumn + gridsizex) // otherwise put it to the right