加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何在没有MouseEvent的情况下在Qt中检测鼠标状态

发布时间:2020-12-16 04:52:56 所属栏目:百科 来源:网络整理
导读:好的,使用Qt,我想知道如何在任何时间点检测鼠标的当前状态 – 没有MouseEvent. 使用QCursor :: pos(),您可以获得它的位置,但有没有办法确定按钮的当前状态? 基本上,我希望在计时器关闭时验证鼠标的状态,因此它不会与任何特定的MouseEvent相关,因此没有要查
好的,使用Qt,我想知道如何在任何时间点检测鼠标的当前状态 – 没有MouseEvent.

使用QCursor :: pos(),您可以获得它的位置,但有没有办法确定按钮的当前状态?

基本上,我希望在计时器关闭时验证鼠标的状态,因此它不会与任何特定的MouseEvent相关,因此没有要查询的MouseEvent.我需要知道如何查询鼠标的状态 – 特别是按钮的状态 – 没有MouseEvent.

哦,我正在使用Qt 3,所以如果在Qt 4中添加了这样的功能但不在Qt 3中,它对我没什么帮助(尽管知道它仍然很好).

解决方法

Qt::MouseButtons QApplication::mouseButtons () [static]:

Returns the current state of the buttons on the mouse. The current
state is updated syncronously as the event queue is emptied of events
that will spontaneously change the mouse state (QEvent::MousePress and
QEvent::MouseRelease events).

It should be noted this may not reflect the actual buttons held on
theinput device at the time of calling but rather the mouse buttons as
last reported in one of the above events. If no mouse buttons are
being held Qt::NoButton is returned.

编辑:嗯,我刚刚注意到你问过Qt3.3.这个答案适用于Qt4我害怕.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读