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 get value from of desired role inside 'onDoubleClicked'
Qt 6.11 is out! See what's new in the release blog

TableView get value from of desired role inside 'onDoubleClicked'

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 2.0k 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.
  • B Offline
    B Offline
    brianrrichter
    wrote on last edited by
    #1

    Hi there, I want to get the value for the role 'id' inside the method 'onDoubleClicked', but the only thing I can get is the row number. I could not use model.data() because there is no class QModelIndex.
    Can someone help me with this?

    TableView {
                id: tview
                Layout.fillWidth: true
                Layout.fillHeight: true
    
                model: dashboardProvider.getModel()
    
                onDoubleClicked: {
                    console.log(row);
                    //dashboardProvider.openWidget(id)
                }
                .
                .
                .
    }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      model.get(row).id

      Ref: https://stackoverflow.com/questions/32956108/qml-tableview-get-data-from-specific-cell-selected-row-specific-column

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brianrrichter
        wrote on last edited by
        #3

        I implemented MyModel class that extends QAbstractTableModel and the get(int row) method

        but I'm getting the following:
        TypeError: Property 'get' of object QAbstractTableModel(0x1ae8030)

        onDoubleClicked: {
                        console.log(model.get(row).id)
        }
        
        1 Reply Last reply
        0
        • B Offline
          B Offline
          brianrrichter
          wrote on last edited by
          #4

          I found a solution:

          onDoubleClicked: {
                          console.log(model.data(model.index(row,0), 256))
                          // 256 => Qt::UserRole
          }
          
          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