I am trying to highlight the currently selected item in a ListView. Below is the code I'm using; for some reason, while similar code works fine in another ListView of this application, the SelectedRectangle element is never displayed here, although the selected element changes when it should.
Rectangle { id: deviceTree width: (window.width * 2) / 3 height: 400 border { width: 2 color: "black" } ListView { id: deviceTreeView model: deviceTreeModel delegate: deviceTreeDelegate highlight: SelectionRectangle {} anchors.fill: parent anchors.margins: 6 } Component { id: deviceTreeDelegate Rectangle { border.color: "#CCCCCC" width: deviceTree.width height: 30 smooth: true radius: 2 MouseArea { anchors.fill: parent onClicked: { deviceTreeView.currentIndex = index; window.selectedDeviceChanged(deviceName) } } } } }
SelectedRectangle.qml
Rectangle { id: selectionRectangle color: "lightsteelblue" smooth: true radius: 5 }
SOLUTION: The rectangle in deviceTreeDelegate was white by default and overlapped the selection rectangle. Using a property, it is set as trasparent, so the selection can be seen.
source share