title: Find screen position of a QGraphicsItem
body: <p>Use case: <em>This should be a fairly common problem. In a normal QMainWindow with QMdiArea lives an mdiChild with a QGraphicsView. This view displays a QGraphicsScene with QGraphicsItems inside. A right-click at one of these items selects (focusses) the item and opens a context menu, which is conveniently placed at the screen coordinates <code>QGraphicsSceneMouseEvent::screenPos()</code>. This is working as expected.</em>  </p>
  
  <p>Now I'd like to show the same context menu when the user presses a key (e.g. Qt::Key_Menu). I know the selected (focussed) item, I know the view which displays the scene.</p>
  
  <p><strong>So my question is:</strong><br>
  What is the correct way to get the position (in global, screen coordinates) of the visible representation of a QGraphicsItem within a scene?</p>
  
  <p>Here is what's not working:</p>
  
  <pre><code>QGraphicsItem *item = ...; // is the currently selected item next to which the context menu shall be opened
  QGraphicsScene *scene = ...; // is the scene that hosts the item
  QGraphicsView *graphicsView = ...; // is the view displaying the scene, this inherits from QWidget
  
  // get the position relative to the scene
  QPointF sp = item-&gt;scenePos();
  // or use
  QPointF sp = item-&gt;mapToScene(item-&gt;pos());
  
  // find the global (screen) position of the item
  QPoint global = graphicsView-&gt;mapToGlobal(graphicsView-&gt;mapFromScene(sp));
  
  // now
  myContextMenu.exec(global);
  // should open the context menu at the top left corner of the QGraphicsItem item, but it goes anywhere
  </code></pre>
  
  <p><a href="http://doc.qt.nokia.com/4.7-snapshot/graphicsview.html#coordinate-mapping" rel="noreferrer">The doc says:</a>
  <em>If you want to know where in the viewport an item is located, you can call QGraphicsItem::mapToScene() on the item, then QGraphicsView::mapFromScene() on the view.</em><br>
  Which is exactly what I'm doing, right?</p>
  
  <hr>
  
  <p>Just stumbled upon <a href="http://www.qtforum.de/forum/viewtopic.php?t=5109" rel="noreferrer">a thread in a german forum</a> that hints to:</p>
  
  <pre><code>QGraphicsView *view = item-&gt;scene()-&gt;views().last();
  </code></pre>
  
  <p>or even nicer:</p>
  
  <pre><code>QGraphicsView *view;
  foreach (view,  this-&gt;scene()-&gt;views())
  {
      if (view-&gt;underMouse() || view-&gt;hasFocus()) break;
  }
  // (use case in the forum thread:) // QMenu *menu = new QMenu(view);
  </code></pre>
  
  <p>Using that might allow a more generalized answer to my question...</p>