Corran
19th September 2006, 19:04
OK, this only relates to Qt 4.2.
Take this sample code:
QGraphicsScene* scene = new QGraphicsScene(this);
scene->addEllipse(QRectF(110, 110, 20, 20)); // a circle with centre 120,120 and diameter 20
QGraphicsItem* item = sceneScene->itemAt(120, 120);
cout << item->scenePos().x() << ", " << item->scenePos().y() << endl;Now I would expect this to return the scene position of the object it found at, i.e. "120, 120" since QGraphicsItem::scenePos() just returns QGraphicsItem::mapToScene(0,0).
However it only ever returns "0, 0".
In fact
cout << item->mapToScene(item->pos()).x() << ", " << item->mapToScene(item->pos()).x() << endl;
cout << item->pos().x() << ", " << item->pos().y() << endl;also all return "0, 0" whereas you would expect at least one of them to return something else.
Is this a feature or a bug? Does anyone else have this problem or know why I am getting this result?
Take this sample code:
QGraphicsScene* scene = new QGraphicsScene(this);
scene->addEllipse(QRectF(110, 110, 20, 20)); // a circle with centre 120,120 and diameter 20
QGraphicsItem* item = sceneScene->itemAt(120, 120);
cout << item->scenePos().x() << ", " << item->scenePos().y() << endl;Now I would expect this to return the scene position of the object it found at, i.e. "120, 120" since QGraphicsItem::scenePos() just returns QGraphicsItem::mapToScene(0,0).
However it only ever returns "0, 0".
In fact
cout << item->mapToScene(item->pos()).x() << ", " << item->mapToScene(item->pos()).x() << endl;
cout << item->pos().x() << ", " << item->pos().y() << endl;also all return "0, 0" whereas you would expect at least one of them to return something else.
Is this a feature or a bug? Does anyone else have this problem or know why I am getting this result?