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. How to connect two QGraphicsViews (creating a minimap)
Forum Updated to NodeBB v4.3 + New Features

How to connect two QGraphicsViews (creating a minimap)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Amazonasmann
    wrote on last edited by
    #1

    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
    resetTransform();
    scaleX=200/rect.width();
    scaleY=200/rect.height();
    scale(scaleX,scaleY);
    setSceneRect(0,0,0,0);
    }

    // if the minimap is clicked, jump to the position...
    void MinimapGraphicsView::mousePressEvent( QMouseEvent* ev )
    {
    QGraphicsView::mousePressEvent(ev);
    if(m_otherView)
    {
    m_otherView->JumpToPosition(ev->pos().x(),ev->pos().y());
    }
    }

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

    Thank you for your help!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Amazonasmann
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kottalovag
          wrote on last edited by
          #4

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

          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