Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TableView - onClicked slot
Forum Updated to NodeBB v4.3 + New Features

TableView - onClicked slot

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thanasis
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • T Thanasis

      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

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Thanasis
        wrote on last edited by
        #3

        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.

        E 1 Reply Last reply
        0
        • T Thanasis

          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.

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Thanasis
            wrote on last edited by
            #5

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

            E 1 Reply Last reply
            0
            • T Thanasis

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

              E Offline
              E Offline
              Eeli K
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved