How to get element position in QML Controls 2 TableView

Just started using QML, decided to use newest QtQuick and Controls 2, and i got stuck by getting element position in TableView. Here's my main.qml:

import QtQuick 2.12
import QtQuick.Controls 2.12

            TableView {
                id: tview
                width: 272
                height: 200
                columnSpacing: 1
                rowSpacing: 1
                model: tablemodel
                          delegate: Rectangle {
                              implicitWidth: genrecell.implicitWidth
                              implicitHeight: 30
                              border.color: "black"
                              border.width: 0.2

                              Text {
                                  id: genrecell
                                  text: tabledata
                                  font.pointSize: 12
                                  leftPadding: 5
                                  rightPadding: 5
                                  anchors.verticalCenter: parent.verticalCenter
                              }
                              ItemDelegate {
                                      id: idel1
                                      width: parent.width
                                      onClicked: console.log(genrecell.text) // i could get text from element, but same element's could be couple
                                  }
                          }
                ScrollBar.vertical: ScrollBar {
                    position: 1.0
                    width: 10
                }
            }

As model i using qt suggested QAbstractTableModel class in tablemodel.cpp:

TableModel::TableModel(QObject *parent) : QAbstractTableModel(parent)

If here are any posibilities to get element position, or i must switch to Controls 1 TableView?

Upvotes: 1

Views: 752

Answers (1)

John Plummer
John Plummer

Reputation: 1

Used this inside my Text {}. It logs the row and column:

                MouseArea{
                    anchors.fill: parent
                    onClicked: {
                        console.log( row, column, index)
                    }
                }

Upvotes: 0

Related Questions