i need to be able to react on focus changes in QWebPage. I used microFocusChanged() signal and it gives me almost desirable behavior, but anyway i don’t know how to know which element is selected. I want to do some actions when any editable element on page gets or loses focus.
Thank you in advance
To handle any HTML event within a page you do the following:
JavaScript to add focus change handlers should traverse all text elements and add onfocus and onblur handlers. Better yet is to add single handler to documentElement and use event bubbling. Unfortunately, onblur ad onfocus do not bubble. Fortunately, they have a bubbling counterparts called DOMFocusIn and DOMFocusOut.
Here’s a complete examlpe of catching focus in/out events for page text elements. It declares two slots
handleFocusInandhandleFocusOuton the main window to be called from JavaScripts and registers main window as a global JavaScript variable namedMainWindow. In then runs JavaScript to bind DOMFocusIn/DOMFocusOut events to these slots (indirectly, because we need to filter out non-text elemnts).(I may rewrite in in C++ if you REALLY can’t figure out Python).