<?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[MousePressEvent called 3 times when double-clicking]]></title><description><![CDATA[<p dir="auto">I have created a class, GraphicPoint, that inherits both QObject and QGraphicsEllipseItem.</p>
<p dir="auto">.h file</p>
<p dir="auto">@#include &lt;QtWidgets&gt;</p>
<p dir="auto">class GraphicPoint : public QObject, public QGraphicsEllipseItem<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
GraphicPoint(qreal x, qreal y, qreal width, qreal height, QWidget *parent = nullptr);</p>
<p dir="auto">signals:<br />
void clicked();</p>
<p dir="auto">private:<br />
void mousePressEvent(QGraphicsSceneMouseEvent *event);<br />
};@</p>
<p dir="auto">.cpp file</p>
<p dir="auto">@#include "graphicpoint.h"</p>
<p dir="auto">GraphicPoint::GraphicPoint(qreal x, qreal y, qreal width, qreal height, QWidget *parent) :<br />
QObject(parent),<br />
QGraphicsEllipseItem(x, y, width, height, nullptr)<br />
{<br />
}</p>
<p dir="auto">void GraphicPoint::mousePressEvent(QGraphicsSceneMouseEvent *event){<br />
event-&gt;accept();<br />
emit clicked();<br />
}@</p>
<p dir="auto">In the main window, I have created a view and a scene and added the point to the scene. Quickly clicking the button twice calls the mousePressEvent 3 times, whereas doing the same a bit slower calls it just 2 times. Here is the main window .cpp file</p>
<p dir="auto">@#include "mainwindow.h"</p>
<p dir="auto">MainWindow::MainWindow(QWidget *parent) :<br />
QMainWindow(parent)<br />
{<br />
n = 0;<br />
view = new QGraphicsView(this);<br />
scene = new QGraphicsScene(this);<br />
view-&gt;setScene(scene);<br />
testPoint = new GraphicPoint(0, 0, 10, 10, this);<br />
connect(testPoint, &amp;GraphicPoint::clicked, <a>this</a>{<br />
n++;<br />
qDebug()&lt;&lt;n &lt;&lt;endl;<br />
});<br />
scene-&gt;addItem(testPoint);<br />
setCentralWidget(view);<br />
}@</p>
<p dir="auto">After 2 quick clicks, QDebug outputs 3 lines with the numbers 1, 2, 3.</p>
<p dir="auto">What can be the reason of this happening? Is there some default doubleclick event that calls the additional mousePressEvent?</p>
<p dir="auto">Additional info:</p>
<p dir="auto">The main.cpp file is as follows:</p>
<p dir="auto">@#include "mainwindow.h"<br />
#include &lt;QApplication&gt;</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{<br />
QApplication a(argc, argv);<br />
MainWindow w;<br />
w.show();</p>
<p dir="auto">return a.exec();<br />
}@</p>
<p dir="auto">and the mainwindow.h:</p>
<p dir="auto">@#include &lt;QtWidgets&gt;<br />
#include "graphicpoint.h"</p>
<p dir="auto">class MainWindow : public QMainWindow<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
MainWindow(QWidget *parent = 0);</p>
<p dir="auto">private:<br />
QGraphicsView *view;<br />
QGraphicsScene *scene;<br />
GraphicPoint *testPoint;<br />
qint32 n;<br />
};@</p>
]]></description><link>https://forum.qt.io/topic/43587/mousepressevent-called-3-times-when-double-clicking</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Nov 2026 08:52:52 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/43587.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Jul 2014 16:42:11 GMT</pubDate><ttl>60</ttl></channel></rss>