<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to connect two QGraphicsViews (creating a minimap)]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">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).<br />
Here is my attempt, which is obviously not working...<br />
@<br />
//scale the minimap according to the big view<br />
void MinimapGraphicsView::scaleToMap(QRectF rect)<br />
{<br />
//rect is the size of the big view<br />
resetTransform();<br />
scaleX=200/rect.width();<br />
scaleY=200/rect.height();<br />
scale(scaleX,scaleY);<br />
setSceneRect(0,0,0,0);<br />
}</p>
<p dir="auto">// if the minimap is clicked, jump to the position...<br />
void MinimapGraphicsView::mousePressEvent( QMouseEvent* ev )<br />
{<br />
QGraphicsView::mousePressEvent(ev);<br />
if(m_otherView)<br />
{<br />
m_otherView-&gt;JumpToPosition(ev-&gt;pos().x(),ev-&gt;pos().y());<br />
}<br />
}</p>
<p dir="auto">//gets called from the minimap when it is clicked..<br />
void TileGraphicsView::JumpToPosition(int x,int y)<br />
{<br />
QRectF old=sceneRect();<br />
setSceneRect(x,y,old.width(),old.height());<br />
}@</p>
<p dir="auto">Thank you for your help!</p>
]]></description><link>https://forum.qt.io/topic/35430/how-to-connect-two-qgraphicsviews-creating-a-minimap</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Nov 2026 20:57:52 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/35430.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Dec 2013 09:16:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to connect two QGraphicsViews (creating a minimap) on Fri, 15 Aug 2014 03:39:54 GMT]]></title><description><![CDATA[<p dir="auto">Hi Amazonasmann,<br />
I meet the same requirement and I am courious if you managed to create that rectangle. :)</p>
]]></description><link>https://forum.qt.io/post/226194</link><guid isPermaLink="true">https://forum.qt.io/post/226194</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Fri, 15 Aug 2014 03:39:54 GMT</pubDate></item><item><title><![CDATA[Reply to How to connect two QGraphicsViews (creating a minimap) on Fri, 13 Dec 2013 12:31:41 GMT]]></title><description><![CDATA[<p dir="auto">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?</p>
]]></description><link>https://forum.qt.io/post/207297</link><guid isPermaLink="true">https://forum.qt.io/post/207297</guid><dc:creator><![CDATA[Asperamanca]]></dc:creator><pubDate>Fri, 13 Dec 2013 12:31:41 GMT</pubDate></item><item><title><![CDATA[Reply to How to connect two QGraphicsViews (creating a minimap) on Fri, 13 Dec 2013 09:37:33 GMT]]></title><description><![CDATA[<p dir="auto">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?</p>
]]></description><link>https://forum.qt.io/post/207275</link><guid isPermaLink="true">https://forum.qt.io/post/207275</guid><dc:creator><![CDATA[Amazonasmann]]></dc:creator><pubDate>Fri, 13 Dec 2013 09:37:33 GMT</pubDate></item></channel></rss>