![]() |
![]() |
很重要--转载声明spa
- 本站文章无特别说明,皆为原创,版权全部,转载时请用连接的方式,给出原文出处。同时写上原做者:朝十晚八 or Twowords
- 如要转载,请原文转载,如在转载时修改本文,请事先告知,谢绝在转载时经过修改本文达到有利于转载者的目的。
qt 如何捕获全屏的鼠标事件,这个帖子上面主要讲述了下嵌入式qt怎么抓取系统级消息,不过从这篇文章中我也看到了但愿,有个回复说winEventFilter支持这种方式,而后我就顺着这个线索找到了nativeEventFilter方法,最终试验成功。
首先是让你本身的类继承自QAbstractNativeEventFilter,而后经过QCoreApplication来注册你的窗口类,代码以下:
app.installNativeEventFilter(m_MainWindow);
最后在nativeEventFilter方法中就能获取到系统级事件,个人qt5.5.观看qt的帮助文档,如图1所示html
图1windows
bool CCailianMainWindow::nativeEventFilter(const QByteArray & eventType, void * message, long * result)
{
if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG")
{
MSG * pMsg = reinterpret_cast<MSG *>(message);
if (pMsg->message == WM_NCMOUSEMOVE)
{
//获取到系统鼠标移动,能够作像qq同样的忙碌检测
}
}
return false;
}
调试结果如图2所示
app
图2post