1

I'm using in my code KeyNavigation.tab property to make navigation workable in qml.

But the control SpinBoxis not working with it. for example if i have a control between it and the element i want it to navigate it wont respect the rule.

I'm going to illustrate with a real example.

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

and

main.qml

import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0

ApplicationWindow {
    id: window
    title: "Stack"
    visible: true
    height: 200
    width: 400
    Item {
        id: page
        anchors.fill: parent
        width:parent.width
        height: parent.height
        ScrollView {
            id:scrollView
            anchors.fill:parent
            Column{
                width:parent.width
                spacing:10
                TextField {
                    id:textField
                    KeyNavigation.tab: spinBox1
                    implicitHeight: 30
                    font.bold: true
                }
                SpinBox {
                    id: spinBox1
                    KeyNavigation.tab: spinBox2
                    width: 100
                    height: 30
                    editable: true
                }
                ComboBox {
                    id:comboBox
                    //KeyNavigation.tab: spinBox2
                    anchors.topMargin: 10
                    textRole: "text"
                }
                SpinBox {
                    id: spinBox2
                    KeyNavigation.tab: textField
                    width: 100
                    height: 30
                    editable: true
                }
            }
        }
    }
}

Here spinBox1 wont jump to spinBox2 if we use tab.

This was tested on a windows 10 OS

The version of Qt used is 5.11.1

6
  • I've tested it in Qt 5.12.1 on Linux and it works correctly Commented Feb 27, 2019 at 10:48
  • Maybe it is related with windows 10 then, it's where i tested. Commented Feb 27, 2019 at 10:56
  • Are you using the latest version of Qt? if so, I think it is a bug so it is recommended that you report it. Commented Feb 27, 2019 at 11:00
  • @yellanesc i'm using Qt Creator 4.8.1 Commented Feb 27, 2019 at 11:23
  • @Nmaster88 I'm not asking you the version of Qt Creator, that's irrelevant. I'm asking you the version of Qt. Commented Feb 27, 2019 at 11:39

1 Answer 1

0

For some reason, the QQuickKeyNavigationAttached::keyPressed() is not called if the attached property is set on the SpinBox itself instead of its TextInput. So, using the attached property on the contentItem is a workaround:

    SpinBox {
        Component.onCompleted: contentItem.KeyNavigation.tab = spinBox
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.