Transfer focus to SwipeView inner element



  • Hi all. What i am trying to achieve: I have custom QML component CustomElem with SwipeView inside. SwipeView by itself can contain different components inside and i want to transfer focus to one of them when CustomElem component take focus.

    For example:
    main.qml loaded --> user push button and one of CustomElem in main.qml becomes focused (elem.focus = true) --> focus is transferred through object hierarchy inside CustomElem, through SwipeView down to element inside the SwipeView, that have property focus: true.

    In my example i want that inner Rectangle activeFocus property becomes true.

    I have QML component CustomElem.qml with following code:

    import QtQuick 2.0
    import QtQuick.Controls 2.2
    
    Item {
        id: rootItem
        objectName: "rootItem"
        width: parent.width
        height: parent.height
    
        SwipeView {
            anchors.fill: parent
            objectName: "swipeView"
    
            Rectangle {
                id: innerRect
                objectName: "rectInRect"
                focus: true
                color: activeFocus ? "orange" : "black"
            }
        }
    }
    

    This component used in main.qml as followed:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        objectName: "window"
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Item {
            id: keyHandler
            objectName: "keyHandler"
        }
    
        CustomElem {
            width: 200
            height: 200
            focus: true
        }
    
        CustomElem {
            width: 200
            height: 200
            y: 200
        }
    }
    


  • Hello,

    I have very similar problem. Did you find any solution?

    poor_robert





  • @poor_robert Hi! I used KeyNavigation.down: swipe.currentItem in the element root Item. But i think it is the same as forceActiveFocus.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.