Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEngineView can not react to keyPressEvent ?
Forum Updated to NodeBB v4.3 + New Features

QWebEngineView can not react to keyPressEvent ?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 2 Posters 3.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anyetiangong
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      anyetiangong
      wrote on last edited by A Former User
      #2

      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

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #3

        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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved