title: How to create a context menu for right click in QGraphicsView
body: <p>I created a graphics view using the designer in Qt creator.</p>
  <p>The hierarchy is the following:</p>
  <p><a href="https://i.stack.imgur.com/h2bNx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h2bNx.png" alt="enter image description here" /></a></p>
  <p>When I do a right click in the area of my graphics view nothing happens (which is the default behavior afaik). Since I'm trying to show a drop down menu on right click but I can't get it to work I added a connect and custom slot.</p>
  <p>Here is my code:</p>
  <pre><code>
  MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow)
  {
     ui-&gt;setupUi(this);
     MainWindow:: makePlot();
  =
     ui-&gt;graphView-&gt;setContextMenuPolicy(Qt::CustomContextMenu);
     
     QObject::connect(ui-&gt;graphView ,SIGNAL(customContextMenuRequested(const QPoint &amp;)),this,SLOT(on_graphView_customContextMenuRequested(const QPoint &amp;)));
     scene = new QGraphicsScene();
     ui-&gt;graphView-&gt;setScene(scene);
  ...
  }
  </code></pre>
  <p>And the slot function that is called to handle the menu:</p>
  <p>`</p>
  <pre><code>void MainWindow::on_graphView_customContextMenuRequested(const QPoint &amp;pos)
  {
  
      qDebug() &lt;&lt; &quot; custom menuu!!!!!!!!!&quot;&lt;&lt;  &quot;##&quot;&lt;&lt; pos.x() &lt;&lt; &quot;  ;  &quot;&lt;&lt; pos.y();
  //    QMenu menu(this);
  //        menu.addAction(&quot;...1&quot;);
  //        menu.addAction(&quot;...2&quot;);
  //        menu.exec(pos);
  }
  </code></pre>
  <p>`</p>
  <p>The problem (s):</p>
  <ol>
  <li><p>the qdebug string is printed twice on my console on each single right click, why does that happen? It is supposed to appear only once...</p>
  </li>
  <li><p>I'm drawing Qgraphicsitems on my scene, the on_graphView_customContextMenuRequested seems to be triggered even when I right click a drawn item and not only a blank space in the scene, how do I get it to trigger only for graphview, in areas with nothing on top (no overlay of item on scene).</p>
  </li>
  <li><p>the coordinates in pos are relative the graphview dimensions, therefore when I uncomment the <code>menu.exec</code> in the above code, the menu is shown in a wrong location. How do I convert my pos to global coordinates relative to the entire Windows and not only the graphicsview.</p>
  </li>
  </ol>