QWebEngineView can not react to keyPressEvent ?
-
I create a class which implements from QWebEngineView, it override the keyPressEvent function. But this function has never called.
Then I run some tests with event function. It works fine with QWidget. Debug info outputed from QWidget event when I pressed a key in the widget:
widget event , event type : 51
widget event , event type : 207 (InputMethodQuery)
widget event , event type : 51
widget event , event type : 51
widget event , event type : 6 (KeyPress)
keypress event : QKeyEvent(KeyPress, key=0x46, text="f")
widget event , event type : 7 (KeyRelease)But there was only 51 in QWebEngineView, which wasn't mentioned in QEvent class:
web engine event , event type : 51
web engine event , event type : 51
web engine event , event type : 51 -
Here is my code :
class WebEnigne : public QWebEngineView { Q_OBJECT public: explicit WebEnigne(QWidget* parent = 0); protected: virtual void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; virtual bool event(QEvent* event) Q_DECL_OVERRIDE; }; WebEnigne::WebEnigne(QWidget* parent) : QWebEngineView(parent) {} void WebEnigne::keyPressEvent(QKeyEvent* event) { // keypressevent has never been called qDebug() << "keypress event : " << event->key(); QWebEngineView::keyPressEvent(event); } bool WebEnigne::event(QEvent* event) { qDebug() << "web engine event , event type : " << event->type(); switch(event->type()) { case QEvent::KeyPress: qDebug() << "web engine key press : "; break; } return QWebEngineView::event(event); }
Edit: Code tags -- @Wieland
-
This posts looks very old, but still not answered. I think keypress event is not working properly in QtWebEngineView. Did you tried the evenfilter mechanism. I tried and it is working well in my Qt WebEngine project. https://wiki.qt.io/How_to_catch_enter_key