title: Get QGraphicsItem by mouse position in QGraphicsScene
body: <p>I am trying to connect two <code>QGraphicsItems</code> by <em>straight line</em> (<code>QGraphicsLineItem</code>); by clicking with middle mouse button on first object, then hover on second object and after I release it, it should draw line between them.</p>
  
  <p>This is function that should connect these items.</p>
  
  <pre><code>void GraphicsBlock::connectBlocks(GraphicsBlock *block)
  {
      GraphicsConnect *connection = new GraphicsConnect(); //Class with QGraphicsLineItem
      connection-&gt;line-&gt;setLine(QLineF(this-&gt;pos(), block-&gt;pos()));
  }
  </code></pre>
  
  <p>I am working on one scene and I've got problem with finding second block by mouse position. Function <code>mousePressEvent</code>  should work with this code:</p>
  
  <pre><code>if(event-&gt;button() == Qt::MiddleButton)
      Connecting == true;
  </code></pre>
  
  <p>and after that <code>mouseReleaseEvent</code></p>
  
  <pre><code>if(Connecting)
  {
      //Get object by mouse position here
      //this.connectBlocks(..)
      Connecting = false;
  }
  </code></pre>
  
  <p>I tried <code>scene-&gt;itemsAt(mouse.x(), mouse.y(), QTransform())</code> and </p>
  
  <p><code>scene-&gt;items(QPointF(mouse.x(),mouse.y())</code> but it always returned <strong>empty list</strong>.</p>
  
  <p>EDIT:
  This is how application should work, blue ellipse is clicked port, now i should drag (still mouse down) to another port and release mouse.</p>
  
  <p><a href="https://i.stack.imgur.com/Suhtb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Suhtb.png" alt="Application image"></a></p>