DelegateModel 的用法:
import QtQuick 2.0
import QtQml.Models 2.2
Rectangle {
width: 200; height: 100
DelegateModel {
id: visualModel
model: ListModel {
ListElement { name: "Apple" }
ListElement { name: "Orange" }
}
delegate: Rectangle {
height: 25
width: 100
Text { text: "Name: " + name}
}
}
ListView {
anchors.fill: parent
model: visualModel
}
}
SpinBox的用法:
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
SpinBox {
property string objectName: ""
property int valueLen: 1
property string upArrow : "qrc:/img/upArrow.png"
property string downArrow : "qrc:/img/downArrow.png"
property color spinBoxTextColor: "#ffffff"
property color spinBoxSelectionTextColor:"#ffffff"
property color spinBoxSelectionColor: "#ffffff"
property color titleColor: "#ffffff"
property string tmpValue:""
property int oldValue: 0
id:spinBox
decimals: 0
horizontalAlignment:Qt.AlignLeft
font.pixelSize:12
activeFocusOnPress:false
onValueChanged: {
valText.text=" "+spinBox.value+" "
}
Rectangle{
anchors.fill: parent
color: "#ffffff"
Text{
id: valText
anchors.fill: parent
color:titleColor
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
font.pixelSize:12
clip: true
MouseArea{
id:mouse2
acceptedButtons: Qt.LeftButton
enabled:true
anchors.fill: parent
onClicked: {
//传用户输入的值到QWidget
}
}
}
}
style: SpinBoxStyle{
background: Rectangle {
implicitWidth: 60
implicitHeight: 30
border.color: "#ffffff"
//radius: 1
border.width: 1
color: "#ffffff"
}
incrementControl :Rectangle { //加
implicitWidth: 18
implicitHeight: 12
color: "transparent"
border.width: 0
Image {
anchors.bottom: parent.bottom
source: styleData.upHovered && !styleData.upPressed
? upArrow : (styleData.upPressed ? upArrow : upArrow)
}
}
decrementControl :Rectangle { //减
implicitWidth: 18
implicitHeight: 12
color: "transparent"
Image {
anchors.top: parent.top
source: styleData.upHovered && !styleData.upPressed
? downArrow : (styleData.upPressed ? downArrow : downArrow)
}
}
textColor: spinBoxTextColor
selectionColor:"transparent"
selectedTextColor:spinBoxTextColor
}
Component.onCompleted: {
valText.text=" "+spinBox.value+" "
}
Connections
{
target:eventManager
onEmitQmlEvent:
{
if(spinBox.objectName===eventName){
spinBox.value = value
}
}
}
}