2014-09-13 57 views
0

在下面的代碼一行可見的TableView:QML:只有行和項目代表

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 
      } 
     } 
    } 
} 

如果我註釋掉線設置行和項目代表(我已經標有「//註釋掉」線),表格呈現的很好,表明我指定的模型是正確的。但是,當我設置行和項目代表時,我只獲取表格的第一行。

有人可以指出我在第二種情況(與行和物品代表)有什麼不對嗎?

回答

1

你的代表是巨大的。 640像素是大多數屏幕高度的一半以上。由於模型不存在,您的代碼無法正常運行,但如果我使用虛擬模型並將高度降低到100像素,則會看到其他項目。另外,即使使用當前的代碼,您也應該能夠向下滾動查看其他項目。

+0

你是對的!我現在感到很蠢。 :P – balajeerc 2014-09-13 06:47:07