区分Qt中的单击事件和双击事件 [英] Distinguish between single and double click events in Qt

查看:1335
本文介绍了区分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

推荐答案

您可以在标题为

You can find answer in the thread titled Double Click Capturing on QtCentre forum;


你可以有一个计时器。在releaseEvent处理程序中启动
定时器,
确保超时时间足够
来处理双击。
然后,在双击事件
处理程序中,您可以停止计时器,
防止它触发。如果没有触发double
click处理程序,
定时器将超时并调用
的插槽,您可以在其中处理
单击。这当然是一个
讨厌的黑客,但有机会工作。

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.

wysota

这篇关于区分Qt中的单击事件和双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆