QML之Repeater重复器

Repeater重复器顾名思义就是重复摆放同一个子项。对于一些共同点很多的子项使用重复器可以让代码看起来更加简洁
Row{
        spacing: 20
        y:100
        x:100
        Repeater{
            id:rep
            model :5 //为重复器提供的数据模型,类型是any
            //类型是数字的话,代表要重复器要创建的数量
            Rectangle{
                height: 100
                width: 100
                radius: 10
                color: "blue"
            }


        }


        Text{
           color: "red"
           font.pixelSize: 30
           text: rep.count  //显示重复器的数量,count为只读属性
        }
    }


Column{
        spacing: 20
        y:100
        x:100
        Repeater{
            id:rep
            model :["hello","world","good"] //为重复器提供的数据模型,类型是any
            //类型是数字的话,代表要重复器要创建的数量
            Text{
                color: "blue"
                font.pixelSize: 40
                text:"modelData:" + modelData
            }
 
  
        }
 
  
        Text{
           color: "red"
           font.pixelSize: 30
           text: rep.count  //显示重复器的数量,count为只读属性
        }
    }
 
  
 
 

你可能感兴趣的:(qml,qt)