Important: Please read the Qt Code of Conduct -

[SOLVED]Show image multiple times using QGraphicsView.

  • Until now I have worked a little bit with properly loading and displaying images using Qt. Something like the code below would do just fine

    QGraphicsScene* scene = new QGraphicsScene();
    QGraphicsView* view = new QGraphicsView(scene);
    QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(image));

    But what I want to do now is to display two independent sets of the same image. So when I choose an Image to load a window will get displayed that shows two copies of the same image. If I zoom in or out in one of those images then the same thing should happen in the other one. In that way I will always see the same portion of the image in both copies.

    So my question has two parts:
    1. How can I display the image I load two times, side by side?
    2. How (if possible) can I retain a link between those images while zooming, panning, etc?

  • One way is to attach two different views on your scene ,the image is added to the scene and the view simply displays what is in the scene.As for zooming and all the other operations you can connect the views slots to the zoom in and zoom out slots for example.This is just a rough idea of how I would go about it.Hope this helps.

  • Thanks for your answer. It certainly is an idea, I'll have to do some tests and see how it goes.

  • I have done some progress but it is still far from functional.

    QRectF viewport1 = m_workspace1->mapToScene(m_workspace1->viewport()->geometry()).boundingRect();

    What I am doing (think I am doing) here is get the visible area relative to the first scene in view one, and then set it as the geometry to view two. The effect is not exactly correct though, as you can easily see by repeating the experiment.

    When I move the image in workspace1 the image in workspace2 does move, but it does so in the opposite direction. So if I drag down my first image, the other one will move up instead of following the downward motion.

  • Solved if above you use


    Do note thought that the second image stops responding after this and you can only interact with the first one.