使用QAbstractButton :: autoRepeat时如何区分按下,释放和长按(How to distinguish between pressed, released and long p

编程入门 行业动态 更新时间:2024-10-21 07:46:46
使用QAbstractButton :: autoRepeat时如何区分按下,释放和长按(How to distinguish between pressed, released and long press when using QAbstractButton::autoRepeat)

我使用Qt 4.8.X在Linux上使用X11和/或Qt-QWS以及从QAbstractButton派生的自定义按钮。 现在我必须区分按下按钮,释放按钮和按住按钮的用户。 为此,我想使用QAbstractButton :: autoRepeat,如本问题所述 。 正如QT文档所述

如果启用了autoRepeat,则会定期发出pressed(),released()和clicked()信号。

那么,当所有三个信号一起发射时,我现在如何区分实际按下,按住和释放按钮? 您的想法非常受欢迎。 谢谢和问候。

I am using Qt 4.8.X on Linux with X11 and/or Qt-QWS with custom buttons derived from QAbstractButton. Now I have to distinguish between a button press, release and the user holding down the button. To do so, I would like to use QAbstractButton::autoRepeat as described in this question. As the QT Documentation states

If autoRepeat is enabled, then the pressed(), released(), and clicked() signals are emitted at regular intervals.

Well, how can I now distinguish between actually pressing down, holding down and releasing the button when all three Signals get emitted together? Your ideas are very welcome. Thanks and greeting.

最满意答案

也许使用autoRepeat不是最好的主意。 我不知道你想要做什么,但我的第一个猜测是关闭autoRepeat。 如果用户按下按钮,您将获得按下的信号。 在该回调中,您可以启动一个在您所需的“自动重复”间隔内触发的计时器。 如果用户再次释放按钮(信号释放),您只需停止或终止计时器。

Maybe using autoRepeat is not the best idea here. I do not know what you want to do exactly, but my first guess would be leaving autoRepeat off. If the user presses the button, you get your pressed signal. In that callback you can start a timer that fires in your desired "auto Repeat" interval. If the user releases the button again (signal released), your just stop or kill the timer.

更多推荐

本文发布于:2023-07-23 18:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按下   distinguish   QAbstractButton   autoRepeat   long

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!