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. [SOLVED] Scroll ListView to Item on Tab Navigation
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Scroll ListView to Item on Tab Navigation

Scheduled Pinned Locked Moved QML and Qt Quick
listviewkeyboard
7 Posts 3 Posters 7.5k Views 3 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.
  • T Offline
    T Offline
    th.thielemann
    wrote on 12 Mar 2015, 15:00 last edited by th.thielemann
    #1

    I have a Qml ListView and want to navigate through the list. Scrolling by mouse is possible. But in case i press the Tab key, the cursor goes to the next element and the list is not scrolled.
    What is necessary to auto-scroll to the selected item.
    Hint: List is not in ScrollView yet.

    P 1 Reply Last reply 12 Mar 2015, 16:41
    0
    • M Offline
      M Offline
      Manfred
      wrote on 12 Mar 2015, 16:16 last edited by
      #2

      Hello,

      maybe the ListView highlightRangeMode property is what you're looking for?
      Hope this helps!

      cheers
      Manfred

      1 Reply Last reply
      0
      • T th.thielemann
        12 Mar 2015, 15:00

        I have a Qml ListView and want to navigate through the list. Scrolling by mouse is possible. But in case i press the Tab key, the cursor goes to the next element and the list is not scrolled.
        What is necessary to auto-scroll to the selected item.
        Hint: List is not in ScrollView yet.

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 12 Mar 2015, 16:41 last edited by
        #3

        @th.thielemann

        I have a Qml ListView and want to navigate through the list. Scrolling by mouse is possible. But in case i press the Tab key, the cursor goes to the next element and the list is not scrolled.

        Can you show an example ?

        What is necessary to auto-scroll to the selected item.

        If you set the currentIndex of the ListView it will set auto scroll to that item.

        //Assuming ListView (view) has those many items
        view.currentIndex = 80
        

        157

        1 Reply Last reply
        0
        • T Offline
          T Offline
          th.thielemann
          wrote on 13 Mar 2015, 07:26 last edited by p3c0
          #4

          Updates of currentIndex are only done if I scroll through the list. But not by tab key navigation.

          Here is an example:

          import QtQuick 2.3
          import QtQuick.Controls 1.2
          import QtQuick.Layouts 1.1
          
          Rectangle {
              id: root
              width: 1024
              height: 550
          
              ListModel {
                  id: personalData
                  ListElement {
                      dataLabel: "Firstname"
                      dataValue: "Herbert"
                  }
                  ListElement {
                      dataLabel: "Lastname"
                      dataValue: "Roth"
                  }
                  ListElement {
                      dataLabel: "Plays"
                      dataValue: "Guitar"
                  }
                  ListElement {
                      dataLabel: "Country"
                      dataValue: "Germany"
                  }
                  ListElement {
                      dataLabel: "Age"
                      dataValue: "65"
                  }
                  ListElement {
                      dataLabel: "Hobby"
                      dataValue: "Walking"
                  }
                  ListElement {
                      dataLabel: "Birthday"
                      dataValue: "14.12.1926"
                  }
                  ListElement {
                      dataLabel: "City"
                      dataValue: "Suhl"
                  }
                  ListElement {
                      dataLabel: "Country"
                      dataValue: "Germany"
                  }
              }
          
          
              ListView {
                  id: listView
                  anchors.top: parent.top
                  anchors.left: parent.left
                  anchors.right: parent.right
                  height: root.height - 50
                  snapMode: ListView.SnapToItem
                  clip: true
                  model: personalData
                  focus: true
          
                  onCurrentIndexChanged: {
                      console.log("\nlistView onCurrentIndexChanged  currentIndex=" + currentIndex);
                      console.log("\nlistView onCurrentIndexChanged  height=" + height);
                      //positionViewAtIndex(currentIndex, ListView.SnapPosition)
                  }
          
                  delegate: Rectangle {
                      height: 66
                      width: 500
                      border.color: "grey"
                      border.width: 1
                      TextInput {
                          anchors.centerIn: parent
                          text: dataValue
                          font.pixelSize: 24
                          activeFocusOnTab: true
                      }
                  }
              }
          }
          

          Edited: Put code after ``` (3 backticks) and close with the same - p3c0

          1 Reply Last reply
          0
          • P Offline
            P Offline
            p3c0
            Moderators
            wrote on 13 Mar 2015, 08:53 last edited by
            #5

            Do you mean by pressing tab it should navigate through each item in ListView ?

            157

            1 Reply Last reply
            0
            • P Offline
              P Offline
              p3c0
              Moderators
              wrote on 13 Mar 2015, 10:00 last edited by
              #6

              If so then I guess FocusScope:

              FocusScope {
                  anchors.centerIn: parent
                  TextInput {
                      text: dataValue
                      font.pixelSize: 24
                      activeFocusOnTab: true
                      onFocusChanged: if(focus) { listView.currentIndex = index }
                  }
              }
              

              157

              1 Reply Last reply
              0
              • T Offline
                T Offline
                th.thielemann
                wrote on 17 Mar 2015, 15:57 last edited by th.thielemann
                #7

                Here is the complete solution:

                import QtQuick 2.2
                import QtQuick.Controls 1.2
                import QtQuick.Layouts 1.1
                import OskPlugin 1.0
                
                Rectangle {
                    id: root
                    width: 1024
                    height: 633
                
                    ListModel {
                        id: personalData
                        ListElement { dataLabel: "Firstname";  dataValue: "Herbert"; }
                        ListElement { dataLabel: "Lastname"; dataValue: "Roth"; }
                        ListElement { dataLabel: "Plays"; dataValue: "Guitar"; }
                        ListElement { dataLabel: "Age"; dataValue: "65";}
                        ListElement { dataLabel: "Hobby"; dataValue: "Walking"; }
                        ListElement { dataLabel: "Birthday"; dataValue: "14.12.1926"; }
                        ListElement {  dataLabel: "City";dataValue: "Suhl"; }
                        ListElement { dataLabel: "Country"; dataValue: "Germany"; }
                    }
                   
                    ScrollView {
                        anchors.fill: parent
                
                        ListView {
                            id: listView
                            anchors.fill: parent
                            clip: true
                            model: personalData
                            focus: true
                
                            delegate: FocusScope {
                                x: rectangle.x;
                                y: rectangle.y
                                width: rectangle.width;
                                height: rectangle.height
                
                                Rectangle {
                                    id: rectangle
                                    height: 66
                                    width: 500
                                    border.color: "grey"
                                    border.width: 2
                                    TextInput {
                                        anchors.centerIn: parent
                                        text: dataValue
                                        font.pixelSize: 24
                                        focus: true
                                        activeFocusOnTab: true
                                        onActiveFocusChanged: if(activeFocus) { listView.currentIndex = index }
                                    }
                                }
                            }
                        }
                    }
                }
                
                1 Reply Last reply
                0

                1/7

                12 Mar 2015, 15:00

                • Login

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