2016-05-09 17 views
1

我在QML中拥有这段代码,但是我无法将STATIC文本添加为​​每列的标题。QML列中的标题

我试过在网上看,但我似乎没有找到asnwer。或者我只是不明白。

Component { 

    id: pedido   
    Item { 
     id: item 
     width: parent.width; 
     Row { 
      id: row 
      width: parent.width 
      anchors.verticalCenter: parent.verticalCenter 
       Column { 
         width: parent.width * 0.3      
         Text {       
          text: " " + codigo; 
          font.family: "Helvetica"                  
          font.pointSize: 14 
          font.bold: true 
          color: item.ListView.isCurrentItem ? "white" : "black"      } 
       Column {        
         width: parent.width * 0.5 
         Text {      
          text: "  " + nombre; 
          font.family: "Helvetica"                
          font.pointSize: 14 
          font.bold: true 
          color: item.ListView.isCurrentItem ? "white" : "black" 
          }  
         } 
       Column { 
         width: parent.width * 0.2       
         Text {      
          text: "  " + fecha; 
          font.family: "Helvetica"                
          font.pointSize: 14 
          font.bold: true   
    } 
}  

如果缺少{},请不要担心。

回答

0

你应该实现你自己的header。更多信息在documentation

让我告诉你一个简单的ListModel & ListView一个例子:

import QtQuick 2.5 
import QtQuick.Window 2.2 

Window { 
    visible: true 
    width: 500 
    height: 500 

    Rectangle { 
     width: 300 
     height: 400 

     Component { 
      id: listDelegate 

      Item { 
       width: 400; 
       height: 50; 

       Row { 
        Column { 
         width: 100 
         Text { text: codigo } 
        } 
        Column { 
         width: 100 
         Text { text: nombre } 
        } 
        Column { 
         width: 100 
         Text { text: fecha } 
        } 
       } 
      } 
     } 

     ListModel { 
      id: listModel 

      ListElement { 
       codigo: "111" 
       nombre: "AAA" 
       fecha: "28/08/2001" 
      } 
      ListElement { 
       codigo: "222" 
       nombre: "BBB" 
       fecha: "28/08/2002" 
      } 
      ListElement { 
       codigo: "333" 
       nombre: "CCC" 
       fecha: "28/08/2003" 
      } 
     } 

     ListView { 
      id: listView 
      anchors.fill: parent 
      model: listModel 
      delegate: listDelegate 
      focus: true 
      header: myheader 
     } 
    } 

    Component {  //instantiated when header is processed 
     id: myheader 
     Rectangle { 
      gradient: mygradient 
      border {color: "#9EDDF2"; width: 2} 
      width: parent.width; height: 50 

      Row { 
       Column { 
        width: 100 
        Text { text: "Codigo" } 
       } 

       Column { 
        width: 100 
        Text { text: "Nombre" } 
       } 

       Column { 
        width: 100 
        Text { text: "Fecha" } 
       } 
      } 
     } 
    } 

    Gradient { 
     id: mygradient 
     GradientStop { position: 0.0; color: "#8EE2FE"} 
     GradientStop { position: 0.66; color: "#7ED2EE"} 
    } 
}