QML DelegateModel、SpinBox

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
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值