Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to stop the tab order to be propagated through SwipeView pages?



  • Consider the following example:

    main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    
    ApplicationWindow
    {
        objectName: "awMain"
        title: qsTr("Hello World")
        width: 640
        height: 480
        visible: true
    
        WQTButtonFrame
        {
            id: frHeader
            objectName: "frHeader"
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.right: parent.right
            height: 35
    
            m_LeftText: "Left Top"
            m_MiddleText: "Center Top"
            m_RightText: "Right Top"
            m_BgColor: "#b02010"
        }
    
        SwipeView
        {
            objectName: "swMain"
            anchors.left: parent.left
            anchors.top: frHeader.bottom
            anchors.right: parent.right
            anchors.bottom: frFooter.top
            activeFocusOnTab: false
    
            WQTPage
            {
                objectName: "paPage1"
                //activeFocusOnTab: false
    
                m_TopText: "Top"
                m_MiddleText: "Center"
                m_BottomText: "Bottom"
                m_BgColor: "#20b010"
            }
    
            WQTPage
            {
                objectName: "paPage2"
                //activeFocusOnTab: false
    
                m_TopText: "Top"
                m_MiddleText: "Center"
                m_BottomText: "Bottom"
                m_BgColor: "#c0b010"
            }
    
            WQTPage
            {
                objectName: "paPage3"
                //activeFocusOnTab: false
    
                m_TopText: "Top"
                m_MiddleText: "Center"
                m_BottomText: "Bottom"
                m_BgColor: "#20b0c0"
            }
        }
    
        WQTButtonFrame
        {
            id: frFooter
            objectName: "frFooter"
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            height: 35
    
            m_LeftText: "Left Bottom"
            m_MiddleText: "Center Bottom"
            m_RightText: "Right Bottom"
            m_BgColor: "#1020b0"
        }
    
        onActiveFocusItemChanged:
        {
            // found an item with active focus?
            if (activeFocusItem)
                // get the object name
                console.log(activeFocusItem.objectName);
        }
    }
    

    WQTPage.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Templates 2.15 as T
    
    T.Page
    {
        property string m_TopText
        property string m_MiddleText
        property string m_BottomText
        property string m_BgColor: "transparent"
    
        objectName: "paPage"
        activeFocusOnTab: false
    
        Rectangle
        {
            objectName: "rcPage"
            anchors.fill: parent
            color: m_BgColor
    
            Button
            {
                objectName: "btTop"
                text: m_TopText
                anchors.top: parent.top
                anchors.horizontalCenter: parent.horizontalCenter
                width: 75
            }
    
            Button
            {
                objectName: "btMiddle"
                text: m_MiddleText
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                width: 75
            }
    
            Button
            {
                objectName: "btBottom"
                text: m_BottomText
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                width: 75
            }
        }
    }
    

    WQTButtonFrame.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Templates 2.15 as T
    
    T.Frame
    {
        property string m_LeftText
        property string m_MiddleText
        property string m_RightText
        property string m_BgColor: "transparent"
    
        objectName: "frFrame"
    
        Rectangle
        {
            objectName: "rcFrameBg"
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.right: parent.right
            height: 35
            color: m_BgColor
    
            Button
            {
                objectName: "btLeft"
                text: m_LeftText
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                width: 75
            }
    
            Button
            {
                objectName: "btMiddle"
                text: m_MiddleText
                anchors.top: parent.top
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.bottom: parent.bottom
                width: 75
            }
    
            Button
            {
                objectName: "btRight"
                text: m_RightText
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                width: 75
            }
        }
    }
    

    This example show an application with a header, a footer, and a main view, which is a SwipeView containing 3 pages. Several buttons are dispatched onto the whole interface, there are 3 in the header, 3 in the footer, and 3 on each page.

    My purpose is to create a tab order, which should work this way: It should start on the left and top button in the header, and pass from left to right, until the last button on the right of a "row" of buttons is reached, then move to the left button on the "row" on the bottom. When the last button on the right and bottom is reached, the tab order should loop to the left and top button.

    The provided above example works as previously described, except for one thing: On the main view, the focus passes through ALL buttons on ALL pages, and isn't limited by the currently shown page.

    So I need to know how to force the tab order chain to ONLY pass through the buttons located on the CURRENTLY SHOWN page, and to IGNORE all the buttons located onto a NON VISIBLE page. However I spent many time to search a solution by myself, without success. It seems that there is no properties neither on the SwipeView nor on the Page to change that. And this puzzle me.

    So my question is: How can I update my above example to achieve the behavior I need with my tab order?

    NOTE for me, let the tab order moving through non-visible pages is a severe bug, and I'm surprised to find so few info about that. Is it a known bug? How other Qt developers are managing a such situation?