Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Show image multiple times using QGraphicsView.
QtWS25 Last Chance

[SOLVED]Show image multiple times using QGraphicsView.

Scheduled Pinned Locked Moved General and Desktop
qgraphicsviewqgraphicsscene
5 Posts 2 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by ealione
    #1

    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));
    scene->addItem(item);
    view->show();
    

    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?

    1 Reply Last reply
    0
    • musimbateM Offline
      musimbateM Offline
      musimbate
      wrote on last edited by
      #2

      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.

      Why join the navy if you can be a pirate?-Steve Jobs

      1 Reply Last reply
      0
      • ealioneE Offline
        ealioneE Offline
        ealione
        wrote on last edited by ealione
        #3

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

        1 Reply Last reply
        0
        • ealioneE Offline
          ealioneE Offline
          ealione
          wrote on last edited by
          #4

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

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

          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.

          1 Reply Last reply
          0
          • ealioneE Offline
            ealioneE Offline
            ealione
            wrote on last edited by ealione
            #5

            Solved if above you use

            m_workspace2->setSceneRect(viewport5);
            

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved