<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem with QtQuick VirtualKeyboard]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">in my application I have a listview with controls like TextField  and Spinner etc. inside delegates.<br />
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.</p>
<p dir="auto">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.</p>
<p dir="auto">Here is a simple example app with two TextFields.</p>
<p dir="auto">main.cpp:</p>
<pre><code>#include &lt;QGuiApplication&gt;
#include &lt;QQmlApplicationEngine&gt;

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();
}

</code></pre>
<p dir="auto">maini.qml:</p>
<pre><code>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 &amp;&amp; Qt.inputMethod.visible) {
            console.log("CURSOR.Y = " + InputContext.cursorRectangle.y);
        }
    }

    Connections {
        target: InputContext
        onInputItemChanged: itemChanged()
    }

}

</code></pre>
<p dir="auto">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.</p>
<p dir="auto">But I'm struggling with the first step of getting the cursor's screen coordinates.</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">Any ideas?</p>
]]></description><link>https://forum.qt.io/topic/78487/problem-with-qtquick-virtualkeyboard</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 01:05:28 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/78487.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 Apr 2017 08:30:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem with QtQuick VirtualKeyboard on Fri, 21 Apr 2017 10:45:35 GMT]]></title><description><![CDATA[<p dir="auto">Sorry,  just found a solution. The signal "onInputItemChanged" was the problem. I changed it to "onFocusEditorChanged" and it works now.</p>
]]></description><link>https://forum.qt.io/post/389093</link><guid isPermaLink="true">https://forum.qt.io/post/389093</guid><dc:creator><![CDATA[aqtuser]]></dc:creator><pubDate>Fri, 21 Apr 2017 10:45:35 GMT</pubDate></item></channel></rss>