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.
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;
}
}
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;
}
}
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.
Bookmarks