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. Problem with QtQuick VirtualKeyboard
Forum Updated to NodeBB v4.3 + New Features

Problem with QtQuick VirtualKeyboard

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 1.1k Views 2 Watching
  • 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.
  • aqtuserA Offline
    aqtuserA Offline
    aqtuser
    wrote on last edited by
    #1

    Hi,

    in my application I have a listview with controls like TextField and Spinner etc. inside delegates.
    What I want is this: when the user taps on a TextField the VirtualKeyboard opens and the view should scroll so that the input item is not covered by it.

    I looked at the AutoScroller example in the documentation and tried to integrate something similar in my application but I always encounter the following problem.

    Here is a simple example app with two TextFields.

    main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char *argv[])
    {
        qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
    
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        return app.exec();
    }
    
    

    maini.qml:

    import QtQuick 2.7
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.1
    import QtQuick.VirtualKeyboard 2.1
    
    Window {
        visible: true
        width: 640
        height: 480
    
        ColumnLayout {
            anchors.centerIn: parent
            spacing: 32
            TextField{
                text: qsTr("Field 1")
            }
            TextField{
                text: qsTr("Field 2")
            }
        }
    
        function itemChanged() {
            if (InputContext.inputItem && Qt.inputMethod.visible) {
                console.log("CURSOR.Y = " + InputContext.cursorRectangle.y);
            }
        }
    
        Connections {
            target: InputContext
            onInputItemChanged: itemChanged()
        }
    
    }
    
    

    The idea is to find the screen coordinates of the current cursor. Then map those coordinates to the ListView's coordinate space and to then scroll the view by setting its contentY property accordingly.

    But I'm struggling with the first step of getting the cursor's screen coordinates.

    It's demonstrated in this simple example. When the user activates one of the TextFields, the cursor position will always be 0 or incorrect the first time. Only an activation of another TextField will from then on give correct results.

    Additionally when using the TextFields in a ListView delegate like I want to do, the cursor position will often reset to 0 after a little bit of scrolling.

    Any ideas?

    1 Reply Last reply
    0
    • aqtuserA Offline
      aqtuserA Offline
      aqtuser
      wrote on last edited by
      #2

      Sorry, just found a solution. The signal "onInputItemChanged" was the problem. I changed it to "onFocusEditorChanged" and it works now.

      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