How to get Keypress event in QWebView



  • 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.*



  • 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()));
    }
    @



  • 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.



  • [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?



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.