简体   繁体   中英

QtQuick QML How to highlight item in ListView on hover?

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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM