I have a scene where several items are added. The problem is that when the items are displayed, they are overlapping. Is there any way to indicate in the QGraphicsView
or QGraphicsScene
the position where each item should appear?
0
votes
Add a comment
|
Yes, you have to use QGraphicsItem::setPos()
method.
I suppose you added a QGraphicsPixmapItem
, so it could look like :
QGraphicsScene *scene = ... ; // your scene
QImage image = ... ; // the QImage you want to add to the scene
QPixmap pixmap = QPixmap::fromImage(image) ;
// add image item to the scene
QGraphicsPixmapItem * imageItem = scene->addPixmap(pixmap) ;
// modify item's position in scene coordinates
QPointF imagePos = ... ; // whatever scene pos you want
imageItem->setPos(imagePos) ;
Not the answer you're looking for? Browse other questions tagged qt qgraphicsview qgraphicsitem qgraphicsscene or ask your own question.
1 Answers
1
votes
Yes, you have to use QGraphicsItem::setPos()
method.
I suppose you added a QGraphicsPixmapItem
, so it could look like :
QGraphicsScene *scene = ... ; // your scene
QImage image = ... ; // the QImage you want to add to the scene
QPixmap pixmap = QPixmap::fromImage(image) ;
// add image item to the scene
QGraphicsPixmapItem * imageItem = scene->addPixmap(pixmap) ;
// modify item's position in scene coordinates
QPointF imagePos = ... ; // whatever scene pos you want
imageItem->setPos(imagePos) ;