Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QtQuick QML How to highlight item in ListView on hover?

Tags:

qt

qml

qtquick2

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

like image 337
FieryRider Avatar asked Dec 05 '25 15:12

FieryRider


1 Answers

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

like image 196
FieryRider Avatar answered Dec 08 '25 07:12

FieryRider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!