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. Cannot override FINAL property for delegate and selection
Qt 6.11 is out! See what's new in the release blog

Cannot override FINAL property for delegate and selection

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 3.9k 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.
  • G Offline
    G Offline
    GrandAlex
    wrote on last edited by Chris Kawa
    #1

    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-qt6

    But 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 property

    What I am doing wrong ?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      @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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrandAlex
        wrote on last edited by
        #3

        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

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

          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
          
          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