How can I catch keystroke to Qt application?

  • Dear all,

    I want to make class to implement with all input widgets such as QLineEdit, QTextEdit & etc...
    During when I focus on that input widgets, if I type "A" on keyboard, that class send respective asian character to focused input widget.

    How can I do that?
    Plz help me...
    Thanks in advance..

  • your question is not clear, can you add some more information.. If you are using QLineEdit or QTextEdit in your application, they automatically handle key events. Do you want to implement a class similiar to QLineEdit ??

    To Catch key events, implement KeyPressEvent, KeyReleaseEvent inside your QWidget class.

  • I would like to make a keyboard layout.
    If I press keyPress on one character, class will send to focused input widget a respective character.
    It like Microsoft keyboard layout for non-English language.

    "QInputContext": can send like that but its example is with "InputPanel.":
    I don't need to click these buttons just to convert keyPressEvent.


  • Ok got you... you need to do couple of things

    1. Write your own class class that derives from QInputContext
    2. Implement filterEvent of QInputContext and do your conversion logic
    3. Call sendEvent () to send your converted character to the focused widget.
    4. Install your QInputContext class on QApplication with setInputContext() method.

    This is what happens, as soon as you press any key event, that event comes to your QInputContext class, you perform the conversion logic, and then send it to focused widget (check if this focused widget is a editor before doing your conversion logic).

  • @bool MyInputMethod::filterEvent(const QEvent *event)
    if (event->type() == QEvent::RequestSoftwareInputPanel){
    return true;
    } else if (event->type() == QEvent::CloseSoftwareInputPanel){
    return true;
    } else if (event->type() == QEvent::KeyPress){
    QMessageBox::about(0,"TEST","Key is Pressed");
    return true;

    return false;


    I try to catch there but no catch to KeyPress
    What's wrong with my method, plz guide me..


  • are you writing your own inputpanel ?? or you just want to do conversion logic inside this class???

  • Yes, I'm trying to make own input method.
    But I don't know where can I catch those KeyPress Event

    I don't want to use platform dependent methods such as iBus, SCIM.
    And this input method is use only for Qt application
    Plz help me

  • Ok.. we did some work on virtual keypads long time back.. There are some tweaks that we need to do to catch events....

    Let me refer back to the work we have done and get back to you..

  • OK
    Really thanks
    what I means is virtual keyboard, that's it :)
    But not on screen keyboard..
    Thanks a lot

  • Have any solutions on this issue?

Log in to reply

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