Hi,
I have an object in the scene and I use mapFromScene to map a point, which is in the item's scene's coordinate system, to the item's coordinate system.
When the item’s transformation matrix is identity, and I move the object around the scene and then I use mapFromScene with the current scenePos, the result is always (0,0). However, if I apply to the item a transformation that scales the object to double its width, and I move the object around the scene and then I use mapFromScene with the current scenePos, the result is different at different places of the scene. See for example:
The object is at the top left of the scene:
***************** Start Map pivot ***************
ScenePos X: 117
ScenePos Y: 67
Transformed X: 9.88098e-15
Transformed Y: 0
Current transformation Matrix:
|---|---|---|
| 2 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
|---|---|---|
***************** End map pivot ***************
The object is at the top right of the scene:
***************** Start Map pivot ***************
ScenePos X: 623
ScenePos Y: 69
Transformed X: 2.9976e-15
Transformed Y: 0
Current transformation Matrix:
|---|---|---|
| 2 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
|---|---|---|
***************** End map pivot ***************
The object is around the center or the scene
***************** Start Map pivot ***************
ScenePos X: 368
ScenePos Y: 218
Transformed X: -5.15143e-14
Transformed Y: 0
Current transformation Matrix:
|---|---|---|
| 2 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
|---|---|---|
***************** End map pivot ***************
Here is the code:
void tnkdesignscene::setTransPivotPoint()
{
refCoordinate = SelectedItem->scenePos();
qgraphicsitem_cast<tnkitemcontainer *>(SelectedItem)->setTransPivotPoint(QVector2D(refCoordinate));
}
void tnkitemcontainer::setTransPivotPoint(QVector2D vector)
{
qDebug() << "***************** Start Map pivot ***************";
qDebug() << "ScenePos X: " << vector.x();
qDebug() << "ScenePos Y: " << vector.y();
transPivotPoint = QVector2D(this->mapFromScene(vector.toPointF()));
qDebug() << "Transformed X: " << transPivotPoint.x();
qDebug() << "Transformed Y: " << transPivotPoint.y();
printMatrix(this->transform());
qDebug() << "***************** End map pivot ***************";
}
void tnkdesignscene::setTransPivotPoint()
{
QPointF refCoordinate;
refCoordinate = SelectedItem->scenePos();
qgraphicsitem_cast<tnkitemcontainer *>(SelectedItem)->setTransPivotPoint(QVector2D(refCoordinate));
}
void tnkitemcontainer::setTransPivotPoint(QVector2D vector)
{
qDebug() << "***************** Start Map pivot ***************";
qDebug() << "ScenePos X: " << vector.x();
qDebug() << "ScenePos Y: " << vector.y();
transPivotPoint = QVector2D(this->mapFromScene(vector.toPointF()));
qDebug() << "Transformed X: " << transPivotPoint.x();
qDebug() << "Transformed Y: " << transPivotPoint.y();
printMatrix(this->transform());
qDebug() << "***************** End map pivot ***************";
}
To copy to clipboard, switch view to plain text mode
Any idea why?
Thanks,
Carlos.
Bookmarks