【发布时间】:2016-04-30 08:25:12
【问题描述】:
我有一个添加了几个项目的场景。问题是当项目显示时,它们是重叠的。有什么方法可以在QGraphicsView 或QGraphicsScene 中指明每个项目应该出现的位置吗?
【问题讨论】:
标签: qt qgraphicsview qgraphicsitem qgraphicsscene
我有一个添加了几个项目的场景。问题是当项目显示时,它们是重叠的。有什么方法可以在QGraphicsView 或QGraphicsScene 中指明每个项目应该出现的位置吗?
【问题讨论】:
标签: qt qgraphicsview qgraphicsitem qgraphicsscene
是的,你必须使用QGraphicsItem::setPos() 方法。
我想你添加了一个QGraphicsPixmapItem,所以它可能看起来像:
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) ;
【讨论】: