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中单击和双击事件的区别
基础教程推荐
- 设计字符串本地化的最佳方法 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01