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?
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?