Well, I think I found the basis of the problem, but I don't know how I could solve it.
The item is the blue line, it's a QGraphicsPixmapItem.
This is the rotated item (45º). The angle is kept into its member variable m_iAngle.
But, when the next code is executed:
//Set the item to angle zero in order to write its true position to the Xml file. Later, rotate it again.
float xx= myItem->pixmap().width() / 2;
float yy = myItem->pixmap().height() / 2;
myItem->setTransform(QTransform().translate(-xx, -yy).rotate(0).translate(xx, yy));
xmlWriter.writeStartElement("x");
xmlWriter.
writeCharacters(QString::number(myItem
->scenePos
().
x()));
xmlWriter.writeEndElement();
xmlWriter.writeStartElement("y");
xmlWriter.
writeCharacters(QString::number(myItem
->scenePos
().
y()));
xmlWriter.writeEndElement();
myItem->setTransform(QTransform().translate(-xx, -yy).rotate(myItem->getAngle()).translate(xx, yy));
//Set the item to angle zero in order to write its true position to the Xml file. Later, rotate it again.
float xx= myItem->pixmap().width() / 2;
float yy = myItem->pixmap().height() / 2;
myItem->setTransform(QTransform().translate(-xx, -yy).rotate(0).translate(xx, yy));
xmlWriter.writeStartElement("x");
xmlWriter.writeCharacters(QString::number(myItem->scenePos().x()));
xmlWriter.writeEndElement();
xmlWriter.writeStartElement("y");
xmlWriter.writeCharacters(QString::number(myItem->scenePos().y()));
xmlWriter.writeEndElement();
myItem->setTransform(QTransform().translate(-xx, -yy).rotate(myItem->getAngle()).translate(xx, yy));
To copy to clipboard, switch view to plain text mode
But my item now appears:
Maybe I should stop using its width and height... but it worked well so far :S
Do you know what should I use instead? or should I renounce to rotate from its center?
Bookmarks