Witam, mam kod qml wyświetlający qui programu, tylko nie wiem jak w kodzie C++ pobrać np. który element ListView jest zaznaczony :
Oto kod QML :
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
width: 1920
height: 1080
visible: true
visibility: "FullScreen"
MouseArea {
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
onClicked: {
Qt.quit();
}
Component{
id: highlightBar
Rectangle {
id: zaz
width: 160
height: 40
y: listView1.currentItem.y
radius: 10
color: 'lightgrey'
}
}
ListView {
id: listView1
x: -5
y: 0
width: 110
height: 512
antialiasing: false
transformOrigin: Item.Center
highlight: highlightBar
highlightFollowsCurrentItem: false
model: ListModel {
id: lvItems
ListElement {
name: "System"
imagesSource: "qrc:/images/linux.png"
}
ListElement {
name: "Procesor"
imagesSource: "qrc:/images/cpu.png"
}
ListElement {
name: "Pamięć RAM"
imagesSource: "qrc:/images/ram.png"
}
ListElement {
name: "Sieć LAN"
imagesSource: "qrc:/images/lan.png"
}
}
delegate: Item {
x: 5
width: 80
height: 40
Row {
id: row1
Rectangle {
width: 40
height: 40
Image {
anchors.fill: parent
fillMode: Image.PreserveAspectFit
source: imagesSource
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("clicked")
listView1.currentIndex = index
}
}
}
Text {
text: name
font.bold: true
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
onClicked: {
console.log("clicked")
listView1.currentIndex = index
}
}
}
spacing: 10
}
}
onCurrentIndexChanged: {
console.log(lvItems.get(currentIndex).name)
}
}
}
}