【问题标题】:How to put several QImage in a QGraphicsView?如何将几个 QImage 放在一个 QGraphicsView 中?
【发布时间】:2016-04-30 08:25:12
【问题描述】:

我有一个添加了几个项目的场景。问题是当项目显示时,它们是重叠的。有什么方法可以在QGraphicsViewQGraphicsScene 中指明每个项目应该出现的位置吗?

【问题讨论】:

    标签: qt qgraphicsview qgraphicsitem qgraphicsscene


    【解决方案1】:

    是的,你必须使用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) ;
    

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多