Results 1 to 2 of 2

Thread: ListView indexAt,itemAt issue

  1. #1
    Join Date
    Sep 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default ListView indexAt,itemAt issue

    I have ListView and i use mouse coordinate check and get index, item from ListView. I use listView.indexAt(x,y), listView.itemAt(x,y), in normal ListView i get them successfully but in ListView i add verticalLayoutDirection: ListView.BottomToTop, listView.indexAt(x,y), listView.itemAt(x,y) can't get value.
    How i can get indexAt, itemAt correct?

    Qt Code:
    1. ListView {
    2. id:list
    3. anchors.fill: parent
    4. interactive: false
    5. verticalLayoutDirection: ListView.BottomToTop
    6. MouseArea {
    7. id:mous
    8. anchors.fill: parent
    9. onPositionChanged: {
    10.  
    11. var positionInRoot = mapToItem(list, mouse.x, mouse.y)
    12.  
    13. var index = list.indexAt(positionInRoot.x,positionInRoot.y) // is not correct when use verticalLayoutDirection: ListView.BottomToTop
    14. var item = list.itemAt(positionInRoot.x,positionInRoot.y) // is not correct when use verticalLayoutDirection: ListView.BottomToTop
    15.  
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ListView indexAt,itemAt issue

    Does using list.height-positionInRoot.y etc. yield proper indices? Why do you need that index value at all? If it is your actual code then MouseArea is the delegate for the view so it is enough to react to onEntered and onExited to store the "current" index on the view. If MouseArea is not your delegate then you can apply MouseArea to the delegate item and re-read the previous sentence of my post.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Signal emit Issue - Listview is not showing full list
    By Mathan in forum Qt Programming
    Replies: 3
    Last Post: 15th October 2016, 17:53
  2. Replies: 2
    Last Post: 17th May 2016, 00:50
  3. issue with loading QML ListView through C++
    By ejoshva in forum Newbie
    Replies: 1
    Last Post: 17th July 2015, 10:57
  4. listview issue
    By joko in forum Qt Quick
    Replies: 0
    Last Post: 13th July 2015, 19:17
  5. QGraphicsPixmapItem and QGraphicsView::itemAt() issue
    By alazar in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2014, 10:59

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.