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. How to use ItemSelectionModel with TableView
Qt 6.11 is out! See what's new in the release blog

How to use ItemSelectionModel with TableView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    I have created a TableView in QML, connected to a SortFilterProxyModel. The data displays fine, and when I click on a row my "selectRow" function runs, and receives the correct row number. However, nothing shows as selected. I based my design on this Stack Overflow question

    The relevant code is:

    ItemSelectionModel {
        id: companyTableISM
        model: companySFPM
    }
    
    function selectRow(row) {
        console.log("In selectRow row "+row);
        companyTableISM.select(companySFPM.index(row, 0), ItemSelectionModel.select | ItemSelectionModel.current );
        console.log(companyTableISM.selectedIndexes);
        console.log(companyTableISM.hasSelection);
    }
    

    So when I click a row it outputs:

    qml: In selectRow row 3
    qml: []
    qml: false
    

    Since my selectRow function is receiving the correct row number, the model (companySFPM) matches the one used by the TableView, why do my 2 log statements showing nothing selected and false (hasSelection)?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @ocgltd said in How to use ItemSelectionModel with TableView:

      ItemSelectionModel.select | ItemSelectionModel.current

      It should be ItemSelectionModel.Select | ItemSelectionModel.Current

      1 Reply Last reply
      0
      • B Bob64 referenced this topic on

      • Login

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