[Qt-interest] Problem with QGraphicsScene/view/item coordinates
Kimmo Viitanen
kviitanen at gmail.com
Sun Aug 8 14:04:48 CEST 2010
Hello,
> // Create the items.
> aimer = new QGraphicsRectItem(200, 350, 10, 10);
> aimer->setBrush(QBrush(QColor(Qt::black)));
I got it working by passing (0, 0) as the (x, y) coordinates
and then explicitly setting the position by calling setPos()
on the items. Anyone care to explain what the (x, y)
coordinates are for in the QGraphicsRectItem
constructor then? It seems that by settings those
the item was drawn at the correct position in the view,
but in the scene it was still at position (0, 0)... Which makes
little sense to me.
Anyway, now that that is sorted...
Is there a way to force the view to render the scene so that the
scene's (0, 0) position is at the top left corner of the view? If I
setAlignment(Qt::AlignLeft | Qt::AlignTop) for the view, it renders
the top-left-most item in the scene at the top left corner, NOT
the origin of the scene. Calling translate() on the view does absolutely
nothing. I can do this by putting an item at position (0, 0) in the scene,
so it's not a big problem.
Thanks.
More information about the Qt-interest-old
mailing list