Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Selecting item in QML TreeView does not change isSelected of item



  • 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 (the isSelected never changes for the item). Can someone explain why?



  • Problem is inconsistency in how QML names its methods. Some are "isSelected" (eg ROW), or "isExpanded" (ITEM), but item uses "selected" instead of "isSelected"



  • Problem is inconsistency in how QML names its methods. Some are "isSelected" (eg ROW), or "isExpanded" (ITEM), but item uses "selected" instead of "isSelected"


Log in to reply