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. Qt6.2 TableView SelectionModel / Rectangle selection not working
Qt 6.11 is out! See what's new in the release blog

Qt6.2 TableView SelectionModel / Rectangle selection not working

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • denishessbergerD Offline
    denishessbergerD Offline
    denishessberger
    wrote on last edited by
    #1

    Hi there,

    I am trying to use a ItemSelectionModel in conjunction with a SelectionRectangle and can not get it to work.

    According to the Qt6 documentation (https://doc.qt.io/qt-6/qml-qtquick-controls2-selectionrectangle.html), this is a minimum example of how to get cell selection working, but nothing really seems to happen.

    I am on Qt 6.2, Ubuntu 20.04.

    Any hints?

    import QtQuick
    import QtQuick.Controls
    import Qt.labs.qmlmodels 1.0
    import QtQuick.Window
    
    Window {
       width: 640
       height: 480
       visible: true
       title: qsTr("Hello World")
    
       TableView {
           id: tableView
           anchors.fill: parent
           clip: true
    
           model: TableModel {
               TableModelColumn { display: "name" }
               rows: [ { "name": "Harry" }, { "name": "Hedwig" } ]
           }
    
           selectionModel: ItemSelectionModel {
               model: tableView.model
           }
    
           delegate: Rectangle {
               implicitWidth: 100
               implicitHeight: 30
               color: selected ? "blue" : "lightgray"
    
               required property bool selected
    
               Text { text: display }
           }
       }
    
       SelectionRectangle {
           target: tableView
       }
    }
    
    1 Reply Last reply
    0
    • TassosT Offline
      TassosT Offline
      Tassos
      wrote on last edited by
      #2

      This behavior is by design.
      You need either to set tableView.interactive: false
      or

      SelectionRectangle { 
        selectionMode: SelectionRectangle.PressAndHold 
      }
      

      It's documented here.

      1 Reply Last reply
      1
      • denishessbergerD Offline
        denishessbergerD Offline
        denishessberger
        wrote on last edited by
        #3

        Thanks!

        Would be great if the example itself would also contain either interactive: false or the selectionMode.

        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