2

I'd like to implement a table view, using QtQuick, allowing multiple selection at cell level, emulating the behaviour of old style QTableView with QAbstractItemView::SelectItems and QAbstractItemView::ExtendedSelection flags enabled.

Which of the QtQuick components may I use?

Tarod
  • 6,732
  • 5
  • 44
  • 50

1 Answers1

1

TableViewonly allow to select rows by default, but you can override the selection behavior by customizing its cell delegate (itemDelegate).

First you'll have to disable the default selection behavior with :

selectionMode: SelectionMode.NoSelection

Then in the itemDelegate you can do something like that :

        itemDelegate: Item {
            property bool isSelected: false

            // When user clicks on a cell, turn the isSelected flag on
            MouseArea {
                anchors.fill: parent
                onClicked: isSelected = !isSelected
            }


            Text {
                anchors.verticalCenter: parent.verticalCenter

                // If this cell is selected, color the text in blue
                color: isSelected ? "blue" : "black"

                text: styleData.value
            }
        }

Be careful as the signals emitted by your TableView will not work as your cells are accepting mouse events. But of course you can implement them easily if you need them.

Blabdouze
  • 1,041
  • 6
  • 12