Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Disable custom QInputContext for single control



  • This is really a QT4 issue, but we are still using QT4 here. We have a custom input context that we assign at the application level to provide virtual keypads on the various text inputs. But for one particular input we do not want the keypad to appear.

    Looking at the API docs, there does appear to be a method to set a widget specific input context (setInputContext), but the question is what to set it to. I first thought maybe NULL, but when I look at a generic app (one which has not had a custom input context assigned), I discover it has an input context ( the "xim" context). This led me to suspect create a "xim" context using the CInputContextFactory and assigning it would be the answer, but what I not sure of is what parent do I use for the factory. Is it the widget I am assigning the context to, or something else.

    So basically, I am looking for the best method, either NULL or creating a context from the factory, and if the later, which QObject should I be using as the parent.

    Thanks,
    Dale Pennington


  • Lifetime Qt Champion

    Hi,

    Is it possible that you explain why that specific input should not have the keypad shown ?



  • @SGaist The app in general is running on a keyboardless system, so we need need virtual keyboards/keypads for most text input. However for this particular window and input, the design specified having a fixed keypad integrated into the window, and to use that for the one input widget and not display the virtual keypad.

    So at the app level, a custom input context is defined to generate the virtual keypad, and we need to suppress it when this particular widget (actually a spinbox), gets the input.


  • Lifetime Qt Champion

    Ok, I am currently not sure you can set a null input context but it's worth a try.

    I don't remember the inner working of QInputContext but I wonder if you could not have a multiple keyboard context and show the keypad at the right place in place of your normal virtual keyboard.



  • Lessons learned from this attempt

    1. Setting an inputContext to NULL has no effect. The inputContext remains on its previous value.
    2. While you can use the QInputContextFactory to create a basic inputContext and install it, since the default context does not process the RequestSoftwareInputPanel event, it eventually gets passed to the app level inputContext and gets processed by the custom inputContext anyways.

    The final fix was to modify the custom inputContext to not display the keypad is the widget in question had a custom property set to true (in this case, I used "NoKeyboard"). This did the job.

    Dale Pennington


  • Lifetime Qt Champion

    Glad you found a solution and thanks for sharing it !

    By the way, how do you "not show" the keyboard ?



  • @SGaist We have a custom input context, that catches the RequestSoftwareInputPanel event, and displays the appropriate virtual keyboard/keypad. All I did was add an extra check for the widget in question having the "NoKeyboard" property (a new DynamicProperty defined for this purpose in our application). In this case, it will just how show the panel.


Log in to reply