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.
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
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.
Code:
Component {
id: cateListDelegate
Rectangle {
id: drawer
width: root.itemWidth
height: cateList.height
radius: 6
color: "#e69400"
TextSrc {
font.pixelSize: sizeInPixel
color: "white"
anchors.left: parent.left
anchors.leftMargin: 4
anchors.right: parent.right
anchors.rightMargin: 4
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
maximumLineCount: 2
anchors.verticalCenter: parent.verticalCenter
text: title
}
MouseArea {
anchors.fill: drawer
onClicked: {
console.log("Main category delegate clicked");
MCategoryGrid.selectMain(index);
cursorPosition(idx) // --> Call a function passing index to get the item
isFocusOnMainlist = true
}
}
}
}
function cursorPosition(idx)
{
console.log("cateList.count: ", cateList.count);
console.log("cursorPosition2::index - ", idx);
let item = cateList.itemAtIndex(idx);
if (item) {
mainCcursor.x = item.x + (mainCcursor.width/2)
mainCcursor.y = item.y;
}
}
I have mentioned in the code comment the place where I intend to call the function by passing index to get the item.