Search code examples
qmltreeviewselected

QML TreeView itemDelegate not indicating isSelected


I have created a simple TreeView in QML, with several levels of nesting. I have also created an "itemDelegate" and a "rowDelegate"; both of which switch background color between red/black bound to their respective isSelected.

When I click on an item the ROW color changes, but the item does not. I confirmed the itemFlag for each item includes ItemsIsSelectable and ItemIsEnabled (default).

My itemDelegate contains:

  Rectangle {
                color: styleData.isSelected ? "red" : "black"

I added a selection to the treeview:

  ItemSelectionModel {
       id: treeViewSelectionModel
       objectName: "treeViewSelectionModel"
       model: treemodel
       onCurrentChanged:{console.log("Selection - current changed from ",previous, " to ", current)}
   }

Which correctly prints out the new/previous selection. So it appears the item is being selected, but not changing color. Can someone explain why?


Solution

  • QQC1 is not consistant, so item uses styleData.selected while row uses styleData.isSelected

    (as noted by Maxim)