简体   繁体   中英

How to install a eventFilter to a WinOS window in Qt?

I have got the handle of a WinOS window,eg. Internet Explorer window, in Qt.I did it in this way: m_hwndUnderCursor= WindowFromPoint(curPoint);

How can I install a eventFilter to m_hwndUnderCursor by QWidget::find(m_hwndUnderCursor)->installEventFilter(this); successfully,so that I can watch m_hwndUnderCursor in Qt without HOOK technology.

I know because m_hwndUnderCursor a pointer to a WinOS window so QWidget::find(m_hwndUnderCursor) always return 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). This is Qt's internal stuff and this is not available to other windows, outside the Qt application. It will only work with windows that are part of the same application that you're calling installEventFilter() from.

For similar reason the QWidget::find() will never give you an existing QWidget in result if you try to find non-Qt window. It works only with windows created within your Qt application. Also see this: Can QWidget::find find widgets from a different process?

You will have to deal with it using native Windows API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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