TableView - onClicked slot



  • 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



  • @Thanasis Works for me after I changed "console.log(color_string)" to "console.log(row)".



  • Thank you for your answer. My problem is that neither "click" nor row or any other message in console.log() is displayed when I select a row from the table. I think that the onClick signal is not triggered.



  • @Thanasis Is the button's "click" message shown? What Qt version do you have and what platform?



  • The "click" message is not shown. I am using UBUNTU 14.04 and have installed qt 5.9.1.



  • @Thanasis Do you see any debug output at all? C++ or QML?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.