Results 1 to 3 of 3

Thread: Looking for an alternative to ListView's itemAtIndex

  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 Looking for an alternative to ListView's itemAtIndex

    As I'm using Qt 5.12, I can't use itemAtIndex which is available since Qt 5.13.
    I can't upgrade my Qt version as I have project/platform restrictions. In this regard, please suggest any alternative that gives similar functionality as itemAtIndex.

    Thank you.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    516
    Thanks
    12
    Thanked 77 Times in 75 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    Hi, how do you get the index for itemAtIndex()?
    Could you show us some code where you would like to use itemAtIndex() if you could?

    Ginsengelf

  3. #3
    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 07:45.

Similar Threads

  1. Replies: 2
    Last Post: 17th May 2016, 00:50
  2. ListView - ListView communication
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 30th October 2015, 11:18
  3. Is there a C++ alternative to QML/Qt Quick?
    By Awareness in forum Newbie
    Replies: 6
    Last Post: 1st May 2013, 00:57
  4. Alternative to sscanf ??
    By Windsoarer in forum Qt Programming
    Replies: 7
    Last Post: 26th June 2009, 09:41
  5. alternative to COM??
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 16: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.