在以下代码中:
Rectangle{
width: { parent==null ? 640: parent.width }
height: { parent==null ? 480: parent.height }
Image {
id: mainBackground
anchors.fill: parent
source: "qrc:///wallDiscoveryBackground"
fillMode: Image.PreserveAspectFit
TableView {
id: wallDiscoveryTable
anchors.margins: parent.width * 0.6
width: parent.width
clip: true
model: discoveredWallsTableModel
TableViewColumn { role: "name"; width: 240; title: "Name" }
TableViewColumn { role: "ipAddress"; width: 240; title: "IP Address" }
TableViewColumn { role: "status"; width: 240; title: "Status" }
rowDelegate: wallDiscoveryRowDelegate //comment out
itemDelegate: wallDiscoveryItemDelegate //comment out
}
Component {
id: wallDiscoveryRowDelegate
Rectangle {
width: wallDiscoveryTable.width
height: 640
}
}
Component {
id: wallDiscoveryItemDelegate
Text {
anchors.verticalCenter: parent.verticalCenter
color: styleData.textColor
text: styleData.value
}
}
}
}
如果我注释掉设置行和项代表的行(我用“//注释掉”标记的行),则表格呈现正常,表明我指定的模型是正确的。但是,当我设置行和项委托时,我只获得表格的第一行。
有人能指出我在第二种情况下出了什么问题(包含行和项目代表)吗?
答案 0 :(得分:1)
你的代表是巨大的。 640像素是大多数屏幕高度的一半。由于模型不存在,您的代码无法正常运行,但如果我使用虚拟模型并将高度降低到100像素,我会看到其他项目。此外,您应该能够向下滚动以查看其他项目,即使使用当前代码也是如此。