Note that there are some explanatory texts on larger screens.

plurals
  1. POmousePressEvent called only from certain areas in scene
    primarykey
    data
    text
    <p>I have an application which draws lines based on different data from cars. I want my application to be able to select the lines drawn, and then make the corresponding item selected in a list on the left as well. The problem is that the mousePressEvent is only called when I press the mousebutton in the leftmost quarter of the scene. When it is called the curveSelected() function works as well, but I can't figure out why I can't invoke the mousePressEvent from the other areas on the scene. </p> <p>First of all I have a mousePressEvent.</p> <pre><code>void DrawingScene:::mousePressEvent ( QGraphicsSceneMouseEvent * event ){ event-&gt;ignore(); bool leftbutton = (event-&gt;button() == Qt::LeftButton); if(leftbutton) { qDebug() &lt;&lt; "leftbutton"; emit leftButtonPress(event-&gt;scenePos()); } QGraphicsScene::mousePressEvent(event); } </code></pre> <p>Later connected:</p> <pre><code>connect(d_scene, SIGNAL(leftButtonPress(QPointF)), this, SLOT(curveSelected(QPointF))); </code></pre> <p>leftButtonPress is the signal emitted. Then I have the function which selects the item in the list. This method seems to work just fine. The problem exists without this function as well.</p> <pre><code>void CurveDrawer::curveSelected(QPointF pos){ QMapIterator&lt;QPair&lt;unitID, QString&gt;, carData*&gt; it(dataMap); while(it.hasNext()){ it.next(); QPainterPath curPath = it.value()-&gt;pathItem-&gt;path(); if(curPath.contains(pos)){ for (int i = 0; i &lt; list-&gt;count(); ++i) { QListWidgetItem* curItem = list-&gt;item(i); if(curItem == it.value()-&gt;listItem){ qDebug() &lt;&lt; "curveSelected"; curItem-&gt;setSelected(true); } } } } } </code></pre> <p>Anyone experienced something similar, or may see some obvious mistakes in my code?</p> <p>EDIT:</p> <p>How can i achieve that the mousePressEvent is called every time I click inside the scene? This is basically what I want it to do. Now it is only called when I click in certain area.</p> <p>I tried to implement it with void DrawGraphicsView;;mousePressEvent(QMouseEvent *event) now, and the same problem existed there. The event just got invoked from certain areas in the scene.</p> <p>The strange thing for me is that when a certain place in the scene is in the left of the viewport it is not possible to invoke the mousepressEvent, but when I scroll the same place to the right in the viewport, then it is suddenly possible to invoke the mousepressEvent. Does this make the problem clearer?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload