How to distinguish between mouseReleaseEvent and mousedoubleClickEvent on QGraphicsScene

笑着哭i 提交于 2019-11-28 14:39:02
Cory Klein

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!