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

Touchscreen Device: TextField can't get Focus and therefore VirtualKeyboard Input Method Not Set



  • Very similar to this and possibly related to (but unfortunately not solved by) this, the TextField below cannot get focus for some reason. This makes the VirtualKeyboard output "Input method not set" to the console.

    Strangely, if I connect a USB mouse, then I can select the TextField. But for some reason, when started without any input device attached, the TextField just cannot get focus (either programatically or from the touchscreen).

    I'm running a minimal Arch Linux ARM install (on a Pi 4B) and start the app through an auto login to tty1 with exec startx my_hacked_app. I'm not sure if Qt expects something from the kernel that its not getting (until the USB mouse is attached, and a click event happens).

    Heres the QML:

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.VirtualKeyboard 2.15
    import QtQuick.VirtualKeyboard.Settings 2.15
    
    // This file is loaded from C++ using a QQuickWidget and displayed in an older QtWidget app I'm hacking on
    Item {
        anchors.fill: parent
    
        Item {
            y: 0
            width: parent.width
            height: parent.height / 2
    
    
            TextField {
                id: searchInput
                anchors.top: parent.top
                anchors.left: parent.left
                width: parent.width / 4
                height: 30
                focus: true // doesn't work, nor did a callback trying to forceActiveFocus()...
                inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase | Qt.ImhNoPredictiveText 
                placeholderText: "Search"
            }
    
           InputPanel {
              id: inputPanel 
              y: parent.height / 2
              anchors.left: parent.left
              anchors.right: parent.right
          }
    }
    

    I've probably overlooked something simple. Any help would be greatly appreciated!

    EDIT: Possibly a case of this bug? (I'm using Qt 5.15.2)



  • As a workaround, I've overidden QWidget::event() in the QQuickWidget derived class (which loads the QML source above):

    bool MyQQuickWidget::event(QEvent* event) {
        if (isEnabled() && !isActiveWindow()) {
            activateWindow();
        }
        return QQuickWidget::event(event);
    }
    

    This allows the TextField to receive focus from the touchscreen alone.

    I don't really understand why the window needs to be manually activated like this. I'm probably doing something wrong, but as it's just a prototype, I'm happy with the solution for now.

    If anyone would care to share some insight, I'd appreciate it.



  • As a workaround, I've overidden QWidget::event() in the QQuickWidget derived class (which loads the QML source above):

    bool MyQQuickWidget::event(QEvent* event) {
        if (isEnabled() && !isActiveWindow()) {
            activateWindow();
        }
        return QQuickWidget::event(event);
    }
    

    This allows the TextField to receive focus from the touchscreen alone.

    I don't really understand why the window needs to be manually activated like this. I'm probably doing something wrong, but as it's just a prototype, I'm happy with the solution for now.

    If anyone would care to share some insight, I'd appreciate it.


Log in to reply