Search code examples
qtqmlqt6

Customizing the InputPanel style in Qt6 or restoring the Qt5 one


Starting from Qt6, seems that the new InputPanel style "hides" the hide keyboard button under the settings one.

Hide keyboard button "hidden" in Qt6

There is a way to restore back the old Qt5 InputPanel layout or someone can explain how I can customize/create a new InputPanel style to replicate the old one?

Hide keyboard button always visible in Qt5

I know that exists a KeyboardStyle type but I cannot understand how to use it.


Solution

  • If you have both Qt6 and Qt5 installed, say, Qt5.15.6 with sources, then you can quickly test Qt5 keyboard layouts in your Qt6 app by adding the following to your main.cpp:

    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
    qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", "C:/Qt/Qt5.15.6/5.15.6/Src/qtvirtualkeyboard/src/virtualkeyboard/content/layouts");
    

    Next, copy the Src/qtvirtualkeyboard/src/virtualkeyboard/content/layouts to a qt5layouts subfolder. Next add the keyboard locales you need. Here en_US and fallback files are added to main.qrc:

    <file>qt5layouts/en_US/dialpad.fallback</file>
    <file>qt5layouts/en_US/digits.fallback</file>
    <file>qt5layouts/en_US/handwriting.fallback</file>
    <file>qt5layouts/en_US/main.fallback</file>
    <file>qt5layouts/en_US/numbers.fallback</file>
    <file>qt5layouts/en_US/symbols.fallback</file>
    <file>qt5layouts/fallback/dialpad.qml</file>
    <file>qt5layouts/fallback/digits.qml</file>
    <file>qt5layouts/fallback/handwriting.qml</file>
    <file>qt5layouts/fallback/main.qml</file>
    <file>qt5layouts/fallback/numbers.qml</file>
    <file>qt5layouts/fallback/symbols.qml</file>
    

    Finally update main.cpp to point to the qt5layouts resources.

        qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
        qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", QByteArray(":/qt5layouts"));
    

    A full working example can be found in my github repo: https://github.com/stephenquan/QtInputPanelDemo

    References: