First decide on the size of your grid and the distance between each gridline. For example a grid that is 100 units high could have a line each 10 units. So if the user is trying to poition an item you just need to calculate the nearest gridline to the current position and snap it to that point. The same goes for the X-axis.
[edit]
So you know the position of your first gridlines, and that each line is
gridSize
pixels on from that. When you need to drop an item into the grid you capture the mouse x and y (not sure how you do that in Qt). Then you just calculate which gridline it is nearest to, something like:
if (mouseX < realLeft || mouseX > realRight)
throw "mouse outside grid"; mouseX -= realLeft; int offset = mouseX % gridSize; if (offset > (gridSize / 2)) mouseX += gridSize - offset; else mouseX -= offset;
[/edit]