Solved click signal fired when I double click, is this normal?
-
I am using Qt 5.10.1 on Linux.
I have a QTableView with both the clicked and doubleClicked signals connected to slots.
When I double click, it fires my clicked slot, then my doubleClicked slot, then my clicked slot again.Is this normal?
If so, how can I tell that the first click is part of the double click so I can treat them differently? -
Hi and welcome to devnet,
Yes it's normal, the double click is not a "standalone event", it's two consecutive single clicks.
Why are you reacting to both ?
-
If so, how can I tell that the first click is part of the double click so I can treat them differently?
In some shape or form, it it your job to wait to see whether a single click event is followed "shortly" by the double click event. For example, upon single click, start a timer: if the double click arrives cancel the timer and do not process the original as a single click; if it does not arrive by the time of timer expiry, then now process the original event as a single click only.
-
Well, let's see how it works ...
void mousePressEvent(QMouseEvent* ev) { qDebug()<<__FUNCTION__;} void mouseReleaseEvent(QMouseEvent* ev) {qDebug()<<__FUNCTION__;} void mouseDoubleClickEvent(QMouseEvent* ev) {qDebug()<<__FUNCTION__;}
On double click, we have the following sequence:
mousePressEvent mouseReleaseEvent mouseDoubleClickEvent mouseReleaseEvent
You only need to look at mousePress and doubleClick events.
For a tableView you can use the following signals:
connect(tableView,SIGNAL(doubleClicked(const QModelIndex &)), ... connect(tableView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), ...
I
-
@mpergand
Ah, I took @SGaist 'sYes it's normal, the double click is not a "standalone event", it's two consecutive single clicks.
to mean that one received single-click events too when double click. Evidently that is not the case from what you write.
@Chris-Bare wrote:
When I double click, it fires my clicked slot, then my doubleClicked slot, then my clicked slot again.
again that implies to me he gets a clicked event.
Yet your:
On double click, we have the following sequence:
mousePressEvent
mouseReleaseEvent
mouseDoubleClickEvent
mouseReleaseEventshows no single click events at all, so I'm confused/lost?
-
@JonB said in click signal fired when I double click, is this normal?:
Yet your:
On double click, we have the following sequence:
mousePressEvent
mouseReleaseEvent
mouseDoubleClickEvent
mouseReleaseEventshows no single click events at all, so I'm confused/lost?
I don't quite follow the posts as well,
but clicked() event is usually a combination out of press event and release event
- mousePressEvent -> pressed()
- mouseReleaseEvent -> released()
- mousePressed and Released inside the area of the Widget or one of its children -> clicked()
so you can have pressed and released events, without triggering clicked.
but prior to a doubleClicke event, you have 6 Signals: pressed, released, clicked, pressed, released, clicked -> doubleclicked
-
@J.Hilk said in click signal fired when I double click, is this normal?:
but prior to a doubleClicke event, you have 6 Signals: pressed, released, clicked, pressed, released, clicked -> doubleclicked
That is precisely my understanding too, i.e. that you do get 2 clicked events as well as the doubled clicked. And that in turn is why I advised the OP in my post above as to how to go about ignoring the clicked events in this situation.
However, it is not what @mpergand claims in his "sequence of events for double-click", and I suspect therefore that his analysis is right, in the politest way.
-
Yet your:
On double click, we have the following sequence:
mousePressEvent
mouseReleaseEvent
mouseDoubleClickEvent
mouseReleaseEventshows no single click events at all, so I'm confused/lost?
A single click means two different events, press and release.
The common paradigm used here says: no action takes place on mouse down, only on mouse up.What do you want to do on first click in a row of your tableWiew ?
Usely, clicking on a row just means selecting it.
On second click, you can allow editing the row.
On double clicking, you can open an dialog (for example)
This is standard beheaviour you havewith signals and slotswith a TableView. -