Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Touchscreen Device: TextField can't get Focus and therefore VirtualKeyboard Input Method Not Set
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 770 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jusko
    wrote on last edited by jusko
    #1

    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)

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jusko
      wrote on last edited by jusko
      #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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved