3
我試圖在一行QML表視圖組件中顯示圖像和文本,我選擇了itemDelegate來完成它,但結果顯示爲每行上的粗體文本和圖像列中的粗體文本顯示圖像和文字。似乎有兩次模型項目正在桌面上顯示。QML表視圖圖像作爲單元格
代碼:
Rectangle{
width:parent.width
height:parent.height
color: "#333333"
id: root
ListModel {
id: live_alertmodel
}
TableView {
// anchors.top: download_bt.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: root.width
height: 100
TableViewColumn {
role: "time"
title: "Time"
width: root.width/4
}
TableViewColumn {
role: "location"
title: "Location"
width: root.width/4
}
TableViewColumn {
role: "alert"
title: "Alert"
width: root.width/4
}
TableViewColumn {
role: "image"
title: "Image"
width: root.width/4
}
model: live_alertmodel
itemDelegate: Item {
Text {
anchors.verticalCenter: parent.verticalCenter
color: styleData.textColor
//elide: styleData.elideMode
text: styleData.value
}
Text {
anchors.verticalCenter: parent.verticalCenter
color: styleData.textColor
//elide: styleData.elideMode
text: styleData.value
}
Text {
anchors.verticalCenter: parent.verticalCenter
color: styleData.textColor
//elide: styleData.elideMode
text: styleData.value
font.bold: false
}
Image {
id: myIcon;
width:root.width/4;
//height:50;
anchors.horizontalCenter: parent.horizontalCenter;
source: styleData.value;
fillMode: Image.PreserveAspectFit
height:20
cache : true;
asynchronous: true;
}
}
Component.onCompleted: {
for(var i=0;i<10;i++)
live_alertmodel.append({ time:"12/15/2015",
location:"location",
alert:"access",
image:"http://images.freeimages.com/images/premium/previews/4852/48521810-globe-icon-flat-icon-with-long-shadow.jpg" })
}
}
}
還看到屏幕截圖中,放出來的外觀與上面的代碼。
任何問題上面的代碼?