PDA

View Full Version : How can I add the graphics rect items to a certain place



learning_qt
8th September 2009, 11:06
Hello,

I use the QGraphicsScene, QGraphicsView and QGraphicsRectItem to display 15 images by 5x3.
But I can not add the rect item in certain place,
I use the function void QGraphicsScene::addItem ( QGraphicsItem * item )from the class QGraphicsScene. only the first image was displayed.

I also used the function void QGraphicsRectItem::setRect ( qreal x, qreal y, qreal width, qreal height ). But I can only set x=0, and y=0.

Please give some help.

Grimlock
8th September 2009, 11:51
From Assistant


void QGraphicsItem::setPos ( const QPointF & pos )

Sets the position of the item to pos, which is in parent coordinates. For items with no parent, pos is in scene coordinates.

The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates.

See also pos(), scenePos(), and The Graphics View Coordinate System.

void QGraphicsItem::setPos ( qreal x, qreal y )

This is an overloaded function.

This convenience function is equivalent to calling setPos(QPointF(x, y)).

scascio
14th September 2009, 10:55
Be aware of relatives coordinates, from your scene, your group or your item, since the geometry of an item is relative to its parent item.

Another point to check if the zValue.

S.Cascio