简体   繁体   English

如何在Qt中的WinOS窗口中安装eventFilter?

[英]How to install a eventFilter to a WinOS window in Qt?

I have got the handle of a WinOS window,eg. 我有一个WinOS窗口的句柄,例如。 Internet Explorer window, in Qt.I did it in this way: m_hwndUnderCursor= WindowFromPoint(curPoint); Qt.I中的Internet Explorer窗口以这种方式完成: m_hwndUnderCursor= WindowFromPoint(curPoint);

How can I install a eventFilter to m_hwndUnderCursor by QWidget::find(m_hwndUnderCursor)->installEventFilter(this); 如何通过QWidget::find(m_hwndUnderCursor)->installEventFilter(this);将eventFilter安装到m_hwndUnderCursor QWidget::find(m_hwndUnderCursor)->installEventFilter(this); successfully,so that I can watch m_hwndUnderCursor in Qt without HOOK technology. 成功了,这样我就可以在没有HOOK技术的情况下在Qt中观看m_hwndUnderCursor

I know because m_hwndUnderCursor a pointer to a WinOS window so QWidget::find(m_hwndUnderCursor) always return NULL. 我知道因为m_hwndUnderCursor是指向WinOS窗口的指针所以QWidget :: find(m_hwndUnderCursor)总是返回NULL。 Is there a way to make it? 有办法吗?

A quick answer is: you cannot do this. 一个快速的答案是:你不能这样做。

A more detailed answer: 一个更详细的答案:

The QObject::installEventFilter() works basing on Qt's events engine (the event loop, events propagation, etc). QObject::installEventFilter()基于Qt的事件引擎(事件循环,事件传播等)工作。 This is Qt's internal stuff and this is not available to other windows, outside the Qt application. 这是Qt的内部资源,在Qt应用程序之外的其他窗口中无法使用。 It will only work with windows that are part of the same application that you're calling installEventFilter() from. 它只适用于您正在调用installEventFilter()的同一应用程序的一部分的窗口。

For similar reason the QWidget::find() will never give you an existing QWidget in result if you try to find non-Qt window. 出于类似的原因,如果您尝试查找非Qt窗口, QWidget::find()将永远不会在结果中为您提供现有的QWidget It works only with windows created within your Qt application. 它仅适用于在Qt应用程序中创建的窗口。 Also see this: Can QWidget::find find widgets from a different process? 另请参阅: QWidget :: find可以从不同的进程中查找小部件吗?

You will have to deal with it using native Windows API. 您将不得不使用本机Windows API处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM