Cannot override FINAL property for delegate and selection
-
Hi all,
I have some troubles when I want to implement selection in my TreeView.
I'm following (well I think I am) the documentation and add the following lines in my delegate :delegate: Item { required property bool selected required property bool current // ... }(source:https://doc-snapshots.qt.io/qt6-6.4/qml-qtquick-tableview.html#selecting-items)
My actual code is:
delegate: TreeViewDelegate { id: treeDelegate required property bool selected required property int row indicator: Rectangle { x: leftMargin + (depth * indentation) width: 10 height: 10 color: "red" y: parent.height / 2 - height / 2 } background: Rectangle { width: parent.width opacity: treeDelegate.selected ? 1 : 0 color: expanded ? "white" : "gray" } contentItem: Text { text: treeDelegate.selected ? "selected" : "blabla" } onClicked: { treeView.selectionModel.select(treeView.modelIndex(treeDelegate.row, 0), ItemSelectionModel.Toggle | ItemSelectionModel.Rows); console.log("clicked:", treeView.model.data(treeView.modelIndex(treeDelegate.row, 0))); console.log("Selection model selected? ", treeView.selectionModel.isSelected(treeView.modelIndex(treeDelegate.row, 0))); console.log("Delegate selected? ", treeDelegate.selected); } }For the record, my model is a simple QFileSystemModel, just for test purposes.
I'm trying to get some inspiration from this post : https://forum.qt.io/topic/139031/problem-with-selection-in-treeview-qt6But I cannot execute my QML code, my view is not loaded because I have an error.
I have the following error on my "require property" :
Cannot override FINAL propertyWhat I am doing wrong ?
-
@GrandAlex said in Cannot override FINAL property for delegate and selection:
required property bool selected
WHy are you declaring the property required property bool selected again ? 'selected' property is from TreeViewDelegate. Use some other name.
-
If I don't add this, my selection system is not available.
Is it not what is advised by the documentation in Qt 6.4, here ? https://doc-snapshots.qt.io/qt6-6.4/qml-qtquick-tableview.html#selecting-items -
you can specify that an existing property should be required without redeclaring it : https://doc.qt.io/qt-6/qtqml-syntax-objectattributes.html#required-properties
In your case:required selected