Qt NextItemFocusChain函数在mac上的qml中不工作?

Qt NextItemFocusChain函数在mac上的qml中不工作?,qt,qml,Qt,Qml,我有一个表单,其中我做了一个自定义字段,它只接受顶部、右侧和底部箭头 但要接受选项卡导航,我将使用以下功能链: nextItemInFocusChain().forceActiveFocus() 问题是,这在windows上起作用,但在mac上不起作用 我有一个公式集来说明问题,在“代码文本字段”旁边,我有一个组合框,当用户单击“代码文本字段”中的选项卡进行导航时 它似乎只导航到其他textFields,而一个spinBox,就像我在示例中所做的那样,似乎有一个textField作为conten

我有一个表单,其中我做了一个自定义字段,它只接受顶部、右侧和底部箭头

但要接受选项卡导航,我将使用以下功能链:

nextItemInFocusChain().forceActiveFocus()

问题是,这在
windows
上起作用,但在
mac上不起作用

我有一个公式集来说明问题,在“代码文本字段”旁边,我有一个
组合框
,当用户单击“代码文本字段”中的
选项卡
进行导航时

它似乎只导航到其他
textFields
,而一个
spinBox
,就像我在示例中所做的那样,似乎有一个
textField
作为
contentItem

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

import QtQuick 2.9
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
            Column{
                width:parent.width
                spacing:10
                TextField {
                    id:textField
                    KeyNavigation.tab: spinBox1
                    implicitHeight: 30
                    font.bold: true
                }
                SpinBox {
                    id: spinBox1
                    width: 100
                    height: 30
                    editable: true
                    Component.onCompleted: contentItem.KeyNavigation.tab = userCodeField
                }
                PanelCodeField {
                    id: userCodeField
                    width: 100
                    height: 30
                    KeyNavigation.tab: comboBox
                }
                ComboBox {
                    id:comboBox
                    anchors.topMargin: 10
                    model: [ "Banana", "Apple", "Coconut" ]
                    KeyNavigation.tab: spinBox2
                }
                SpinBox {
                    id: spinBox2
                    width: 100
                    height: 30
                    editable: true
                    Component.onCompleted: contentItem.KeyNavigation.tab = textField
                }
            }
    }
}
import QtQuick 2.0

PanelTextField {
    height: 479.9
    visible: true
    maximumLength: 5
    font.pointSize: 12
    property bool jumpOnTab: false
    Keys.onPressed: {
        var c
        switch (event.key) {
        case Qt.Key_Up:
            c = String.fromCharCode(0x25B2)
            break
        case Qt.Key_Down:
            c = String.fromCharCode(0x25BC)
            break
        case Qt.Key_Right:
            c = String.fromCharCode(0x25B6)
            break
        case Qt.Key_Tab:
            if(jumpOnTab)
                nextItemInFocusChain().nextItemInFocusChain().forceActiveFocus()
            else
                nextItemInFocusChain().forceActiveFocus()
            event.accepted = true
            break
        default:
            event.accepted = true
            break
        }
        if (!event.accepted) {
            var s = text.concat(c)
            text = s.substr(Math.max(0,s.length-maximumLength), maximumLength)
            event.accepted = true
        }
    }
}
import QtQuick 2.0
import QtQuick.Controls 2.0

TextField {
    property var linkedData
    implicitHeight: 30
    font.bold: true
    implicitWidth:parent.width
}
PanelTextField.qml

import QtQuick 2.9
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
            Column{
                width:parent.width
                spacing:10
                TextField {
                    id:textField
                    KeyNavigation.tab: spinBox1
                    implicitHeight: 30
                    font.bold: true
                }
                SpinBox {
                    id: spinBox1
                    width: 100
                    height: 30
                    editable: true
                    Component.onCompleted: contentItem.KeyNavigation.tab = userCodeField
                }
                PanelCodeField {
                    id: userCodeField
                    width: 100
                    height: 30
                    KeyNavigation.tab: comboBox
                }
                ComboBox {
                    id:comboBox
                    anchors.topMargin: 10
                    model: [ "Banana", "Apple", "Coconut" ]
                    KeyNavigation.tab: spinBox2
                }
                SpinBox {
                    id: spinBox2
                    width: 100
                    height: 30
                    editable: true
                    Component.onCompleted: contentItem.KeyNavigation.tab = textField
                }
            }
    }
}
import QtQuick 2.0

PanelTextField {
    height: 479.9
    visible: true
    maximumLength: 5
    font.pointSize: 12
    property bool jumpOnTab: false
    Keys.onPressed: {
        var c
        switch (event.key) {
        case Qt.Key_Up:
            c = String.fromCharCode(0x25B2)
            break
        case Qt.Key_Down:
            c = String.fromCharCode(0x25BC)
            break
        case Qt.Key_Right:
            c = String.fromCharCode(0x25B6)
            break
        case Qt.Key_Tab:
            if(jumpOnTab)
                nextItemInFocusChain().nextItemInFocusChain().forceActiveFocus()
            else
                nextItemInFocusChain().forceActiveFocus()
            event.accepted = true
            break
        default:
            event.accepted = true
            break
        }
        if (!event.accepted) {
            var s = text.concat(c)
            text = s.substr(Math.max(0,s.length-maximumLength), maximumLength)
            event.accepted = true
        }
    }
}
import QtQuick 2.0
import QtQuick.Controls 2.0

TextField {
    property var linkedData
    implicitHeight: 30
    font.bold: true
    implicitWidth:parent.width
}

我是否对mac os x做了一些错误的操作,或者是否有解决方法?

打开
系统首选项>键盘>快捷键
,然后选择
所有控件
。默认情况下,macOS仅允许在“仅文本框和列表”之间进行选项卡导航


我明白了,但有没有办法绕过操作系统的限制?我不知道。