Qt中单击和双击事件的区别

Distinguish between single and double click events in Qt(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中单击和双击事件的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Unresolved external symbol quot;public: virtual struct QMetaObject const * __thiscall Parent(未解析的外部符号“public: virtual struct QMetaObject const * __thiscall Parent)
QVector vs QList(QVector 与 QList)
How to create/read/write JSON files in Qt5(如何在 Qt5 中创建/读取/写入 JSON 文件)
Qt: How do I handle the event of the user pressing the #39;X#39; (close) button?(Qt:如何处理用户按下“X(关闭)按钮的事件?)
STL or Qt containers?(STL 还是 Qt 容器?)
Sort filenames naturally with Qt(使用 Qt 自然地对文件名进行排序)