PDA

View Full Version : Why does QGraphicsItem::scenePos() return (0,0)



extrakun
20th July 2009, 06:40
Hi all,

I am trying to implement a drawing canvas with QGraphicsView and QGraphicsScene. What is perplexing is that after I add a new item to the scene, it's scenePos() is always (0,0). As a trial I test out the following code:


QGraphicsLineItem * anotherLine = this->addLine(50,50, 100, 100);
qDebug() << anotherLine->scenePos();

QGraphicsLineItem * anotherLine2 = this->addLine(80,10, 300, 300);
qDebug() << anotherLine2->scenePos();

Where the this pointer is a class derived from QGraphicsScene. The output for both line is QPointF(0,0).

To my understanding, scenePos() should be returning the position of the QGraphicsItem within the scene itself, but right now it is acting as if it is returning the origin of the item within its own local coordinate. What am I doing wrong?

wagmare
20th July 2009, 06:47
and pos() value returns ..?
Returns the position of the item in parent coordinates.

extrakun
20th July 2009, 06:58
and pos() value returns ..?
Returns the position of the item in parent coordinates.

It still returns QPointF(0,0)...

extrakun
20th July 2009, 07:35
I realise my mistake. I should be doing this instead:



// Length/angle of line
QGraphicsLineItem * newLine = addLine(0,0, 100, 100);

// Move it to where i want it to be inside the scene
newLine->setPos(50,50);