Update and reset the text color of Selected List Item
Solved
QML and Qt Quick
-
Hi,
I am trying to update and reset the text color of current selected list item and resetting the color to default on change in the current list item. But all the time the items are selected with default color
Any help is appreciated, please find my code belowmain.qml
import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") ListView { id: lv anchors.fill: parent model: ListModel { ListElement {name: "Hai"} ListElement {name: "Hai1"} ListElement {name: "Hai2"} ListElement {name: "Hai3"} ListElement {name: "Hai4"} ListElement {name: "Hai5"} ListElement {name: "Hai6"} ListElement {name: "Hai7"} } delegate: MsgItemDelegate { onButtonClicked: { lv.currentIndex = index console.error("==============ListView.currentIndex==>", ListView.isCurrentItem) } } highlight: Rectangle { color: "lightsteelblue"; radius: 5 } } }
MsgItemDelegate.qml
import QtQuick 2.9 import QtQuick.Controls 2.2 ItemDelegate { id: root signal buttonClicked MouseArea{ anchors.fill: parent onClicked: { root.buttonClicked() } } Label { id: txtLbl text: model.name color: lv.isCurrentItem ? "white" : "blue" } }
Thanks in advance !
Regards,
AROH -