PDA

View Full Version : QGraphicsItem maintain constant size on zoom of parent



Casper14
11th June 2014, 16:05
I have implemented what is essentially a map on which the user can draw crosses to indicate points. The map itself is a subclassed QGraphicsView and the crosses are two QGraphicsLineItems. When the user zooms/drags on the map, I want the crosses to move with the map, but not to grow in size.

I draw the crosses with two lines (http://qt-project.org/doc/qt-4.8/qgraphicsscene.html#addLine-2):

QGraphicsLineItem *line_ver = this->scene()->addLine(pt.x(), pt.y()-100, pt.x(), pt.y()+100, QPen(Qt::yellow, 3));
QGraphicsLineItem *line_hor = this->scene()->addLine(pt.x()-100, pt.y(), pt.x()+100, pt.y(), QPen(Qt::yellow, 3));

Then I set them to ignore transformations (http://qt-project.org/doc/qt-4.8/qgraphicsitem.html#GraphicsItemFlag-enum):

line_ver->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
line_hor->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);

This satisfies the first of my requirements, i.e., the crosses do not become larger when the user zooms in, and they also move along when the user drags the map. However, when the user zooms on the map, then the crosses move away from their original positions. Is there any flag I can set to prevent this, or any other way? Thanks!