Important: Please read the Qt Code of Conduct -

How to connect two QGraphicsViews (creating a minimap)

  • Hello Qt Forum, I have a big QGraphicsView in the middle and a small QGraphicsView(minimap) at the top both sharing a QGraphicsScene together. Now I want to visualize where the user is looking in the big map by drawing a red rectangle (the area the user see's in the big view) in the small view, similiar to most strategy games. I want to click on the minimap and the big view jumps to the position which is clicked in the minimap.

    I need some kind of mapping the coordinates and set the position of the big view when the minimap is clicked, but i have no clue how to do this at the moment ( I also have no clue how to draw the red rectangle in the minimap).
    Here is my attempt, which is obviously not working...
    //scale the minimap according to the big view
    void MinimapGraphicsView::scaleToMap(QRectF rect)
    //rect is the size of the big view

    // if the minimap is clicked, jump to the position...
    void MinimapGraphicsView::mousePressEvent( QMouseEvent* ev )

    //gets called from the minimap when it is clicked..
    void TileGraphicsView::JumpToPosition(int x,int y)
    QRectF old=sceneRect();

    Thank you for your help!

  • Ok, i just found the QGraphicsView::centerOn() function. This works for now..but then, the rectangle problem is still there. I want to show a red rectangle in the minimap, but not in the big view. This seems impossible because those two views share the same scene...does anyone see a way how to do this?

  • Can you subclass QGraphicsView, and implement the paintEvent in such a way that you first call the paintEvent of QGraphicsView, then paint the rectangle on top of it?

  • Hi Amazonasmann,
    I meet the same requirement and I am courious if you managed to create that rectangle. :)

Log in to reply