Distinguish between single and double click events in Qt(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.
威索塔
这篇关于Qt中单击和双击事件的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Qt中单击和双击事件的区别


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01