<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[how to get the current index on click of an image for table view]]></title><description><![CDATA[<p dir="auto">i have a requirement where i have to implement fav/unfav on table view</p>
<p dir="auto">i have created a model on the c++ side and got the UI on the QML side</p>
<p dir="auto">the QML code is</p>
<pre><code>Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Table View Example")

    TableView {
        id:peopleTable
        anchors.fill: parent

        signal editfinished(string new_string, string original_string)
        onEditfinished: {
            console.log("this signal called ",new_string, " and ",original_string)
            peopleModel.writeData(new_string , original_string)
        }

        clip: true
        model: peopleModel

        TableViewColumn {
            id: firstColumn
            title: "First_Name"
            property var something: delegate.item
            role: "one";
            width: 200;
            delegate: firstColumnComponent
        }

        Component{
            id:firstColumnComponent
            Item {
                id: toplevelItem
                property bool textpresent: true
                Row{
                    spacing: 10
                    TextField{
                        id:te
                        width: 100
                        text: styleData.value
                        maximumLength: 20
                        onAccepted:{
                            console.log("the editing is finished to",te.text)
                            peopleTable.editfinished(te.text,styleData.value)
                        }
                    }
                    Image {
                        id: fav_image
                        source: "qrc:/favourite_icon.png"
                        height: 20
                        width: 40
                        MouseArea{
                            anchors.fill: parent
                            onClicked: {
                                console.log("the current index is",peopleTable.currentRow)
                            }
                        }
                    }
                }
            }
        }
</code></pre>
<p dir="auto">What happens is when i click the favourite image i get the currentRow as -1 thats because my row is not selected, is There a way to select the row on click of the delegate image, or obtain the corresponding row on click.</p>
<p dir="auto">My UI looks like this.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/f478edd4-0b9e-4ebb-b571-9c2e39b94f6f.png" alt="d72e4c46-5a24-42fc-8d3c-0430016430eb-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/130309/how-to-get-the-current-index-on-click-of-an-image-for-table-view</link><generator>RSS for Node</generator><lastBuildDate>Tue, 16 Jun 2026 08:30:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/130309.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Sep 2021 10:33:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to how to get the current index on click of an image for table view on Wed, 15 Sep 2021 12:02:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vinaygopal">@<bdi>vinaygopal</bdi></a><br />
according to the documentation:</p>
<p dir="auto"><a href="https://doc.qt.io/qt-5/qml-qtquick-controls-tableviewcolumn.html#delegate-prop" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qml-qtquick-controls-tableviewcolumn.html#delegate-prop</a></p>
<p dir="auto">this should do the trick:</p>
<pre><code>Component{
            id:firstColumnComponent
            Item {
                id: toplevelItem
                property bool textpresent: true
                Row{
                    spacing: 10
                    TextField{
                        id:te
                        width: 100
                        text: styleData.value
                        maximumLength: 20
                        onAccepted:{
                            console.log("the editing is finished to",te.text)
                            peopleTable.editfinished(te.text,styleData.value)
                        }
                    }
                    Image {
                        id: fav_image
                        source: "qrc:/favourite_icon.png"
                        height: 20
                        width: 40
                        MouseArea{
                            anchors.fill: parent
                            onClicked: {
                                console.log("the current index is",styleData.row) //Change happened here
                            }
                        }
                    }
                }
            }
        }
</code></pre>
]]></description><link>https://forum.qt.io/post/680688</link><guid isPermaLink="true">https://forum.qt.io/post/680688</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Wed, 15 Sep 2021 12:02:54 GMT</pubDate></item></channel></rss>