Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Transfer focus to SwipeView inner element
Forum Update on Monday, May 27th 2025

Transfer focus to SwipeView inner element

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    egor.utsov
    wrote on last edited by
    #1

    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
        }
    }
    
    DiracsbracketD 1 Reply Last reply
    0
    • P Offline
      P Offline
      poor_robert
      wrote on last edited by
      #2

      Hello,

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

      poor_robert

      E 1 Reply Last reply
      0
      • E egor.utsov

        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
            }
        }
        
        DiracsbracketD Offline
        DiracsbracketD Offline
        Diracsbracket
        wrote on last edited by
        #3

        @egor.utsov
        Maybe this post would help?
        https://forum.qt.io/topic/93347/focus-issue-in-swipeview-with-loader

        1 Reply Last reply
        0
        • P poor_robert

          Hello,

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

          poor_robert

          E Offline
          E Offline
          egor.utsov
          wrote on last edited by egor.utsov
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved