Onscreen Keyboard in Qt 5

Jai picture Jai · Sep 24, 2013 · Viewed 25.1k times · Source

I want to create a onscreen keyboard for a desktop application. The application will be built in Qt 5. I have couple of questions, please clarify them.

  1. What is the replacement of QInputContext in Qt5? (Because I read somewhere about onscreen keybord by implementing QInputContext but this is not supported by Qt 5.)

  2. Where can I find QPlatformInputContext and QInputPanel (on an internet search I found these two as alternatives of QInputContext but not sure about that and also I was unable to find them)?

My requirements:

  1. Keyboard will not use QML or any external library (already build other keyboards).

  2. Keyboard will use Qt Gui (traditional).

Answer

user1055604 picture user1055604 · Sep 26, 2013

I understand there are two challenges you would have:

  1. Getting notified as to when to show/hide the on-screen keyboard, based on the focus being on text widgets
  2. How to post key-press event to the text widgets

ANSWER

  1. As for the former, you could use QObject::InstallEventFilter() on widgets that you want to provide the keyboard service to. You can then look for the mouseReleaseEvent along the lines of the Qt code in the link.
  2. This can be achieved by using QCoreApplication::postEvent()

As for QPlatformInputContext, get the example of a Qt Virtual Keyboard here.