Results 1 to 3 of 3

Thread: Get the first element of a ListView

  1. #1
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Get the first element of a ListView

    Hi all,

    I'm quite newbie with QML.
    I'm managing the focus changing (by tab/back-tab) on all my application.
    I was able to manage it for all my items except for the ListView.

    When tab is hit, in my listView I want to do something like:
    Qt Code:
    1. [...]
    2. var firstElement = getFirstElement();
    3. firstElement.forceActiveFocus();
    4. [...]
    To copy to clipboard, switch view to plain text mode 

    I don't want to use currentIndex if possible because I'm trying to use common APIs for all components. I want a way to get the element.

    In my code the problem is the function called "getFirstElement".
    I've tried to get the element by
    Qt Code:
    1. listView.children[0].children[0]
    To copy to clipboard, switch view to plain text mode 
    but don't works because "listView.children[0].children" is not aligned to the model. I've read that ListView loads the internal element dynamically.. therefore the index 0 is not the first element but only the first visible list element.

    I also tried to store the listView children when component is loaded but the problem is that in that moment are loaded only visible list elements.

    In other words what I need would be: how can I get a complete list of all the elements of the ListView?
    is there a way to get it?

    thank you

  2. #2
    Join Date
    Sep 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Get the first element of a ListView


  3. #3
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Get the first element of a ListView

    No.. or I don't think so..

    I need the deletege component.. or better i need the list of all delegate component sorted as the model to do something like this (in my library that manage focus):

    Qt Code:
    1. sortedChildren[0].forceActiveFocus();
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. sortedChildren[n].forceActiveFocus();
    To copy to clipboard, switch view to plain text mode 


    edit:
    I've tried with:
    Component.onCompleted:
    {
    positionViewAtEnd()
    }
    something is changed but the order of the children is still wrong compared to the model
    Last edited by nick85; 2nd September 2013 at 14:01.

Similar Threads

  1. Qml Listview
    By ganeshgladish in forum Newbie
    Replies: 1
    Last Post: 19th June 2013, 08:41
  2. ListView inside another element
    By Dp0H in forum Qt Quick
    Replies: 0
    Last Post: 24th September 2012, 12:44
  3. should i use listview ?
    By rimie23 in forum Qt Programming
    Replies: 20
    Last Post: 9th May 2012, 22:40
  4. Replies: 9
    Last Post: 23rd April 2012, 13:53
  5. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 12:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.