Results 1 to 3 of 3

Thread: Looking for an alternative to ListView's itemAtIndex

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Looking for an alternative to ListView's itemAtIndex

    Thanks for the reply.
    I have a ListView & it's delegate. I get the index in the delegate's MouseArea. Here is the code snippet of the delegate for your perusal.

    Qt Code:
    1. Component {
    2. id: cateListDelegate
    3. Rectangle {
    4. id: drawer
    5. width: root.itemWidth
    6. height: cateList.height
    7. radius: 6
    8. color: "#e69400"
    9.  
    10. TextSrc {
    11. font.pixelSize: sizeInPixel
    12. color: "white"
    13. anchors.left: parent.left
    14. anchors.leftMargin: 4
    15. anchors.right: parent.right
    16. anchors.rightMargin: 4
    17. horizontalAlignment: Text.AlignHCenter
    18. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
    19. maximumLineCount: 2
    20. anchors.verticalCenter: parent.verticalCenter
    21. text: title
    22. }
    23.  
    24. MouseArea {
    25. anchors.fill: drawer
    26.  
    27. onClicked: {
    28. console.log("Main category delegate clicked");
    29. MCategoryGrid.selectMain(index);
    30.  
    31. cursorPosition(idx) // --> Call a function passing index to get the item
    32.  
    33. isFocusOnMainlist = true
    34. }
    35. }
    36. }
    37. }
    38.  
    39. function cursorPosition(idx)
    40. {
    41. console.log("cateList.count: ", cateList.count);
    42. console.log("cursorPosition2::index - ", idx);
    43. let item = cateList.itemAtIndex(idx);
    44.  
    45. if (item) {
    46. mainCcursor.x = item.x + (mainCcursor.width/2)
    47. mainCcursor.y = item.y;
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 

    I have mentioned in the code comment the place where I intend to call the function by passing index to get the item.
    Last edited by rawfool; 3rd February 2023 at 06:45.

Similar Threads

  1. Replies: 2
    Last Post: 16th May 2016, 23:50
  2. ListView - ListView communication
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 30th October 2015, 10:18
  3. Is there a C++ alternative to QML/Qt Quick?
    By Awareness in forum Newbie
    Replies: 6
    Last Post: 30th April 2013, 23:57
  4. Alternative to sscanf ??
    By Windsoarer in forum Qt Programming
    Replies: 7
    Last Post: 26th June 2009, 08:41
  5. alternative to COM??
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 15:02

Tags for this Thread

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.