[Qt-interest] translate vs setPos

Brian McKinnon bpmckinnon.qt at gmail.com
Tue Nov 30 17:14:43 CET 2010


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, QByteArray
& byteArray, QGraphicsItem * parent) :
    QGraphicsRectItem(parent)
{
    QDataStream dataStream(&byteArray, QIODevice::ReadOnly);

    qint32 version;
    QRectF rect;
    QBrush brush;
    QPen pen;

    dataStream >> version;

    if(version >= 0)
    {
        dataStream >> rect;
        dataStream >> brush;
        dataStream >> pen;
    }

    setRect(rect);
    setBrush(brush);
    setPen(pen);
    setFlag(QGraphicsItem::ItemIsMovable, true);

    //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 tried setPos, moveBy, and translate.  They all produce
the correct result as soon as the object is created.

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 ignoring the
setPos or moveBy value.  If I use translate the item moves from the correct
position... but translate if deprecated.  Am I doing something wrong with
setPos and moveBy... do I need to call a follow-up function to apply the
setPos operation?

Brian!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101130/3363d0f0/attachment.html 


More information about the Qt-interest-old mailing list