[Qt-interest] translate vs setPos
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Tue Nov 30 18:17:50 CET 2010
On 2010-11-30 Brian Brian McKinnon wrote:
> Hi everyone,
>
> I'm having some trouble with creating objects and setting there
> position. I use the code below to create an object after the completion of a drag operation.
>
> DragableRectangleItem::DragableRectangleItem(const QPointF & pos, ...);
> ....
> //setPos(pos.x(), pos.y()); // <- Doesn't work
> //moveBy(pos.x(), pos.y()); // <- Doesn't work
> //translate(pos.x(), pos.y()); // <- Works } At the bottom I have
> The problem is that once I click and move the item positioned with
> setPos or moveBy it jumps back to the origin of the rect completely
Well, where does the parameter 'pos' come from? From the mouse event->pos()? Note that this will give you the *parent* mouse coordinate, so (I assume, did not verify) for a mouse event in a QGraphicsScene the parent would be the underlying item! So you probably want to initialize the parameter 'pos' with something like event->scenePos(), such that you get the global scene coordinates instead (because that is where the user would expect the item to be placed ;)
Does that help?
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list