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. QML TreeView set active item
QtWS25 Last Chance

QML TreeView set active item

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 4.8k 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.
  • L Offline
    L Offline
    LMdV
    wrote on 13 May 2015, 18:26 last edited by
    #1

    Hi,

    Does anyone know how to set the active item in a QML TreeView from javascript?
    The currentIndex property is read-only. Is there any way to set the index?

    Thanks

    1 Reply Last reply
    1
    • B Offline
      B Offline
      Buck Yeh
      wrote on 14 Jul 2015, 08:46 last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • B Offline
        B Offline
        Buck Yeh
        wrote on 14 Jul 2015, 09:41 last edited by
        #3

        Ok, I have solved this.

        import QtQml.Models 2.2

        TreeView {
        id: viewPerSe
        selection: ItemSelectionModel {
        model: viewPerSe.model
        }
        }
        function select (idx) {
        viewPerSe.selection.setCurrentIndex(idx, ItemSelectionModel.ClearAndSelect)
        }

        You are welcomed!

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Niak74
          wrote on 16 Sept 2015, 08:49 last edited by
          #4

          Hi,

          Sorry for replying to this old topic but I have a similar problem :

          I would like to set the currentIndex (which is read only for a TreeView) in order to navigate throught items from the given currentIndex using the keyboard.

          Settings selection is OK, but it does NOT set the currentIndex, so pressing down arrow selects the first item of the TreeView, as currentIndex is still undefined at this step...

          Here some code to select :

          var index = controller.activeFolderIndex;
          treeViewSelectionModel.setCurrentIndex(index, ItemSelectionModel.ClearAndSelect);
          //then I would like something like : treeView.currentIndex = index;

          Any idea ?

          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