Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get Keypress event in QWebView
Forum Updated to NodeBB v4.3 + New Features

How to get Keypress event in QWebView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.0k Views 1 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
    aashish.lg
    wrote on last edited by
    #1

    I am using QWebView to display some flash content in this. I have been set the attribute of this window to be frameless and made it as a child window of some other process(Remote desktop Terminal session window).

    I wanted to grab the ALT+F4 key press combination on this flash video. I mean to say if user clicks on the flash video(i.e. my QWebView window is in focus now), at that time if user presses ALT+F4, then I wanted to take some action on this event.

    I have overridden keypressevent(QKeyEvent), but I am not getting this to be called , even though after setting the focus policy.
    *
    NOTE :- I am getting key press event only and only when user click on the QWebView window outside the flash area.*

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on last edited by
      #2

      Maybe some code would help us better understand what is going on...

      If you have the keypress event in the outter most class (so if your using mainWindow, then do it in the mainWindow class), than any object created within the main window that gets clicked should trigger that event, although, ive never done this with a QWebview

      For example:
      @
      /*
      // key press event (virtual protected)
      */
      void MainWindow::keyPressEvent(QKeyEvent *event)
      {
      // append the key press to the list
      keysPressed.append(QString(event->key()));

      // check the key combinations
      if (keysPressed.contains(QString(Qt::Key_Alt)) && keysPressed.contains(QString(Qt::Key_F4))){
            // do what you want here
      }
      

      }

      /*
      // key release event (virtual protected)
      */
      void MainWindow::keyReleaseEvent(QKeyEvent *event)
      {
      // remove the key press from the list
      if (keysPressed.contains(QString(event->key())))
      keysPressed.removeAll(QString(event->key()));
      }
      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aashish.lg
        wrote on last edited by
        #3

        Thanks you for your reply, I tried to do that , nevertheless I am not getting.
        If I create my webview using below mention line.

        webView = new QWebView(this);, then only I am getting this, but it will display webview in my main window dialog , that I dont want. Because of this I am avoiding this-- in the constructor of the QWebView.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          guziemic
          wrote on last edited by
          #4

          [quote author="Ashish Mittal" date="1346326654"]

          I have overridden keypressevent(QKeyEvent), but I am not getting this to be called , even though after setting the focus policy. [/quote]

          From which class did you overridden keyPressEvent?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aashish.lg
            wrote on last edited by
            #5

            Hi,

            I have overriden keypressevent in mainwindow.cpp from QMainWindow class, and in my webview it has been overriden from QWebView.

            Actually the concept here is that this QWebView is creating one more window internally and flash is rendering on top of that , that is the reason I am not getting any key, mouse press event.

            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