Qt中单击和双击事件的区别
我有一个 QAbstractItemView
需要对单击和双击事件做出反应.根据是单击还是双击,操作会有所不同.出现的问题是在双击事件之前接收到单击事件.
I have a QAbstractItemView
that needs to react to single and double click events. The actions are different depending on whether it was single clicked or double clicked. The problem that is occurring is that the single click event is received prior to the double click event.
是否有推荐的方法/最佳实践来区分两者?当用户实际双击时,我不想执行单击操作.
Is there a recommended way/best practice for distinguishing between the two? I don't want to perform the single click action when the user has actually double clicked.
我使用的是 Qt 4.6
I am using Qt 4.6
推荐答案
您可以在标题为 在 QtCentre 论坛上的双击捕获;
You can find answer in the thread titled Double Click Capturing on QtCentre forum;
你可以有一个计时器.启动releaseEvent 处理程序中的计时器和确保超时时间足够长首先处理双击.然后,在双击事件中处理程序,您可以停止计时器和防止它开火.如果双单击处理程序未触发,计时器将超时并调用一个插槽您的选择,您可以在哪里处理单击.这当然是一个讨厌的黑客,但有机会工作.
You could have a timer. Start the timer in the releaseEvent handler and make sure the timeout is long enough to handle the double click first. Then, in the double click event handler you can stop the timer and prevent it from firing. If a double click handler is not triggered, the timer will timeout and call a slot of your choice, where you can handle the single click. This is of course a nasty hack, but has a chance to work.
威索塔
相关文章