0
votes
qt - How to put several QImage in a QGraphicsView? - Stack Overflow
Asked
Viewed 1k times
0

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?

    1

    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) ;
    

      Your Answer

      By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

      Not the answer you're looking for? Browse other questions tagged or ask your own question.

       
      1

      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) ;