3
votes

I have the following QML:

menuBar: MenuBar {...}
header: ToolBar {...}
SplitView {
    id: splitView
    ...
    Item {
        SplitView.preferredWidth: parent.width / 2
        Component {
            id: modDelegate
            GridLayout {
                id: modGrid; columns: 2; columnSpacing: 30
                MouseArea {
                    z: 0; anchors.fill: parent; hoverEnabled: true
                    onEntered: ???; onExited: ???
                }
                CheckBox {}
                ColumnLayout {
                    Layout.topMargin: 5
                    Text {...}; Text {...}; Text {...}; Text {...}
                }
            }
        }
        ListView {
            id: modList; anchors.fill: parent; model: ModModel {}; delegate: modDelegate; focus: true
        }
        Layout.fillHeight: true
    }
    Item {
        SplitView.preferredWidth: parent.width / 2
        ...
    }
}

I want when I hover over an item of that ListView, that item to be visually highlighted (without preventing me from clicking the checkbox inside it of course).

1
did you have a look at highlight property of the ListView? it basically highlights the currentIndex.cppiscute
My problem was that I couldn't find how to set the currentIndex to the item's index that I hover on. But I just found info in another question's answer on how to set the currentIndex to the selected index. I just didn't saw anything in the docs about being able to use index in the delegate to access the current item index. So with that I solved my problem.FieryRider

1 Answers

2
votes

I found a way to solve this in another unrelated question's answer.
I didn't saw anywhere in the docs anything mentioning that I can get the index of the item/delegate I'm in just by using index from inside the delegate. So I just wrapped everything inside modDelegate into Item and set the MouseArea's onEntered property to modList.currentIndex = index