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. Focus issue in SwipeView with Repeater
Forum Updated to NodeBB v4.3 + New Features

Focus issue in SwipeView with Repeater

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 1 Posters 588 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Suli Sahne
    wrote on last edited by
    #1

    Hello,

    once again I have no idea what is going on with the SwipeView.

    There is already a forum post about focus problems with SwipeView and Loader, where forceActiveFocus() helped at the end. But that did not work for me.

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    
    Window {
        width: 200
        height: 200
        visible: true
        title: qsTr("Hello World")
        Item {
            anchors.fill: parent
            SwipeView {
                id: swipe
                anchors.fill: parent
                focus: true
                Repeater {
                    id: rep
                    model: 3
                    Rectangle {
                        id: rec1
                        property bool isCurrItm: ListView.isCurrentItem     // (1)
                        //property bool isCurrItm: SwipeView.isCurrentItem  // (2)
                        //property bool isCurrItm: index === 0              // (3)
                        height: 100
                        width: 100
                        color: rec1.activeFocus ? "gray" : "green"
                        Rectangle {
                            id: rec2
                            height: 50
                            width: 50
                            focus: rec1.isCurrItm
                            color: rec2.activeFocus ? "black" : "red"
                        }
                    }
                }
            }
        }
    }
    

    Using (1) property bool isCurrItm: ListView.isCurrentItem works as expected:

    73f664e1-069a-4024-8e5d-49d559e7dc1f-grafik.png

    (2) and (3) don't:

    fcef88cb-84ae-4e57-bd6f-436456e0c486-grafik.png

    Any ideas why the attached property of a ListView works?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Suli Sahne
      wrote on last edited by
      #2

      Sorry to be confused.. I just want the inner rectangle (rec2) of the currentItem of the SwipeView to have activeFocus and therefore the color black.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Suli Sahne
        wrote on last edited by Suli Sahne
        #3

        Ok, to keep it simple and more understandable. I removed the Repeater and used a TextField instead of the internal Rectangle. Then I want the cursor to blink in the TextField when my component is displayed, so that the user can write something into the TextField immediately without having to click on it.

        In my understanding the TextField should have the activeFocus after loading. But it does not.

        import QtQuick 2.12
        import QtQuick.Window 2.12
        import QtQuick.Controls 2.12
        
        Window {
            id: window
            width: 200
            height: 200
            visible: true
            title: qsTr("Hello World")
            Item {
                anchors.fill: parent
                SwipeView {
                    id: swipe
                    anchors.fill: parent
                    focus: true
                    Rectangle {
                        id: rec
                        height: 100
                        width: 100
                        color: activeFocus ? "gray" : "green"
                        TextField {
                            id: txt
                            focus: true
                            text: activeFocus ? "focus" : "no focus"
                        }
                    }
                }
            }
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          Suli Sahne
          wrote on last edited by Suli Sahne
          #4

          I need a FocusScope for the SwipeView items. Then everything works as intended.

          import QtQuick 2.12
          import QtQuick.Window 2.12
          import QtQuick.Controls 2.12
          
          Window {
              id: window
              width: 200
              height: 200
              visible: true
              title: qsTr("Hello World")
              Item {
                  anchors.fill: parent
                  SwipeView {
                      id: swipe
                      anchors.fill: parent
                      focus: true
                      FocusScope {
                          id: scope
                          focus: SwipeView.isCurrentItem
                          Rectangle {
                              anchors.fill: parent
                              color: activeFocus ? "gray" : "green"
                              TextField {
                                  focus: true
                                  text: activeFocus ? "focus" : "no focus"
                              }
                          }
                      }
                  }
              }
          }
          

          Also adding the Repeater again works!
          Thanks for listening..

          1 Reply Last reply
          1

          • Login

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