0
votes

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?

1
From what you have posted of your Rectangle it is not possible to tell but do you set it's size / anchors?pooya13
According to documentation you should use styleData.selected not styleData.isSelectedMaxim Skvortsov
@Maxim - that was it! Seems QML is not consistent with naming methods for styleData.TSG

1 Answers

0
votes

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

(as noted by Maxim)