Alex G.P.
Alex G.P.

Reputation: 10028

How to distinguish between mouseReleaseEvent and mousedoubleClickEvent on QGraphicsScene

I am overriden QGraphicsScene and overload 2 methods: mouseDoubleClickEvent and mouseReleaseEvent. I want different logic executing on each of this event, but I do not know how to distinguish it? At least 1 mouseReleaseEvent occured before mouseDoubleClickEvent.

Upvotes: 0

Views: 1687

Answers (1)

Cory Klein
Cory Klein

Reputation: 55910

For the logic that you want to occur on a double click, put the code inside mouseDoubleClickEvent() and for the logic that you want to occur on a mouse release, put the code inside mouseReleaseEvent().

If you want to do something when the user clicks but doesn't double click, you have to wait to see if they click twice or not. On the first mouse release start a 200ms timer.

If you get a mouseDoubleClickEvent() before the timer expires then it was a double click and you can do the double click logic. If the timer expires before you get another mouseDoubleClick() then you know it was a single click.

Pseudocode

main()
{
    connect(timer, SIGNAL(timeout()), this, SLOT(singleClick()));
}

mouseReleaseEvent()
{
    timer->start();
}

mouseDoubleClickEvent()
{
    timer->stop();
}

singleClick()
{
    // Do single click behavior
}

This answer gives a rather similar solution.

Upvotes: 2

Related Questions