Important: Please read the Qt Code of Conduct -

[solved] Exporting a QGraphicsView from one QFrame to another

  • Hello there!

    For these days I have been thinking of a new feature for my project. Currently the application has a canvas where users can draw simple vectorial lines, but I would like to provide the next option:

    • When users do "Ctrl+Something" I want that a new QFrame shows up, covering the whole screen and containing a copy of the canvas (including all the graphic objects). Basically the idea is to offer a "zoom experience" (full screen) of the canvas. In my dreams, I would love that if users draw over the new QFrame (full screen), all the new changes appear in the original (small) canvas. Finally, when users want to back to the normal interface, they just have to press "Esc" key and that's all.

    For some weird reason I'm thinking that there's a chance of make this feature come true using a QGraphicsView, nevertheless I'm just guessing, because it's not just a "Zoom tool", understanding that events over the full screen QFrame must be reflected into the original canvas.

    Taking advance of the many experts around this forum... I would like to read comments/advices/ideas about how to design this feature. Is this possible? am I just dreaming? or in fact, is it simpler than I thought?

    Thanks! :)

  • a graphicsScene can have several views. so you work with one scene in your regular view. then pass the pointer to the new, zoomed view (it can also show a different part of the scene) and show in on to of your regular view.

    all changes on an item will appear on both views then, because the scene is actually the data model of the view.

  • Just attach another QGraphicsView to your QGraphicsScene and set the transformation on the second view such that it is zoomed in. Take a look at the 40,000 chips demo that ships with QT to see how this is done. That demo uses 4 views onto a single scene.

  • Thank you so much guys! Now I have the hint I was looking for :)

  • Qt is incredible! I got the solution in few lines relatively:

    1. I create a QDialog based class with my QGraphicsScene object (scene) as constructor parameter
    2. Inside the QDialog I created a QGraphicsView variable (graphicsView)
    3. I set the Scene to the View doing: graphicsView->setScene(scene);
    4. I included the QGraphicsView object inside the Layout of the QDialog:
    5. When I open the dialog... voilĂ !

    I need to work in some details around, but the result is impressive!

    Thank you again guys :)

Log in to reply