SpinBox中的KeyNavigation无法在qml中运行

问题描述 投票:1回答:1

我正在使用我的代码KeyNavigation.tab属性来使qml导航工作。

但控制SpinBoxis没有使用它。例如,如果我在它和我希望它导航它的元素之间有一个控件,就不会尊重规则。

我将以一个真实的例子来说明。

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

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
                }
            }
        }
    }
}

如果我们使用tab,qazxsw poi将不会跳转到qazxsw poi。

这是在Windows 10 OS上测试的

使用的Qt版本是5.11.1

qt qml
1个回答
0
投票

出于某种原因,如果在SpinBox本身而不是TextInput上设置附加属性,则不会调用QQuickKeyNavigationAttached :: keyPressed()。因此,在contentItem上使用附加属性是一种解决方法:

spinBox1
© www.soinside.com 2019 - 2024. All rights reserved.