TableView - onClicked slot
Unsolved
QML and Qt Quick
-
Hello,
I have created a simple QML app which displays a table and three buttons. What I would like to do is to click on a row and display in terminal "click" and the row number. As I have read in the documentation the clicked signal is what I am looking for. I have added the onClicked slot in my QML code but nothing happens. Could you please help me ?
My code is the following:
import QtQuick 2.9 import QtQuick.Window 2.3 import QtQuick.Controls 2.2 import QtQuick.Controls.Styles 1.4 import QtQuick.Layouts 1.3 import QtQuick.Controls 1.4 Window { visible: true width: 640 height: 300 title: qsTr("Hello World") TableView { x: 0 y: 0 width: 500 height: 120 enabled: true sortIndicatorVisible: false TableViewColumn { role: "title" title: "Title" } TableViewColumn { role: "author" title: "Author" } TableViewColumn { width: 300 delegate: Text { text: model.title + " " + model.author font.family: "Courier New" font.pixelSize: 18 color: "red" } } onClicked: { console.log(" click ") console.log(color_string) } model: mymodel ListModel { id: mymodel ListElement { title: "123" author: "green" } ListElement { title: "456" author: "green" } ListElement { title: "789" author: "red" } } } Grid { id: grid x: 531 y: 0 width: 109 height: 300 spacing: 10 rows: 4 columns: 1 Button { text: qsTr("Set") id: button0 onClicked: { console.log(" click ") } } Button { id: button1 text: qsTr("Process") } Button { id: button2 text: qsTr("Save") } } }
Thank you in advance for your help,
Thanasis