[Qtwebengine] KeyPressEvent not implemented?
jocelyn.turcotte at digia.com
Thu Jan 29 18:43:25 CET 2015
Sorry for the late answer, I was looking at the possible ways of dealing
with the issue.
On Sat, Jan 17, 2015 at 09:27:49AM -0800, David Cortesi wrote:
> From: Florian Bruhin <me at the-compiler.org>
> > Out of curiosity: What are you working on exactly?
> A simple reader for web comics:
> I think this is the same limitation as in
> > https://bugreports.qt.io/browse/QTBUG-43602
> > Mouse events are caught by a child QWidget of the QWebEngineView,
> > and not by the QWebEngineView itself. This is a limitation of the
> > current QtWebEngine design.
> I think you are correct. In my opinion this is an awful
> design choice, as it effectively eliminates not only
> mouse events as noted, but (it seems) keypress events.
> It would seem not impossible for this hidden "child widget"
> to pass events along to its parent. That might be tricky
> to implement, but it would keep the tricky-ness inside Qt
> instead of encouraging developers to proliferate their
> own obscure and fragile work-arounds.
It can't pass events to its parent since Chromium has multiple underlying
widgets for a single QWebEngineView, part of it because they need to be
able to seamlessly switch from one to another when navigating between
pages backed by different QtWebEngineProcesses. Sending those events to the
common QWebEngineView first would mean that we'd have to demultiplex them
afterward in a possible QWebEngineView::keyPressEvent implementation,
which would surely bring a few bugs when dealing with edge cases.
I don't know how you can do this in python, but for key events you have
the option of using QAction, QShortcut or a general application event
filter as described in http://doc.qt.io/qt-5/qcoreapplication.html#notify.
If you only want the key events to be intercepted when the web view has
the focus you currently can only do the event filter trick on the
QWebEngineView's chidren as mentioned in QTBUG-43602.
For the general case where you would want to give priority to the web page
and get unhandled key events instead of intercepting them, I uploaded a
fix at https://codereview.qt-project.org/104901 that should be released
with 5.5.0. This will propagate unhandled events back to the parent, which
we are currently never doing in 5.4.
I hope this helps a bit.
More information about the QtWebEngine