How to distinguish between mouseReleaseEvent and mousedoubleClickEvent on QGraphicsScene

前端 未结 1 506
别那么骄傲
别那么骄傲 2020-12-12 06:58

I am overriden QGraphicsScene and overload 2 methods: mouseDoubleClickEvent and mouseReleaseEvent. I want different logic executing on

相关标签:
1条回答
  • 2020-12-12 07:24

    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.

    0 讨论(0)
提交回复
热议问题