如何用QML创建自定义对象



我试图在QML中创建一个自定义对象,但是没有成功。我是不是漏掉了什么重要的小事?

下面是代码

some.qml

import QtQuick 2.0
Rectangle {
    id: devicesList
    width: 100
    height: 62
    color: "red"
   ListElement {}
}

ListElement.qml

import QtQuick 2.0

Rectangle {
    id: aaa
    x: 100
    y: 100
    //x: ListElementRoot.xx
   // y: ListElementRoot.yy
    width: 100
    height: 100
    radius: 10
    color: "blue"
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        hoverEnabled: true
        onEntered:{
            animation.start()
            animation2.start()
            animation3.start()
        }
        //onClicked: aaa.width -= 10
        //onEntered:
    }
    PropertyAnimation {
        id: animation
        target: aaa
        properties: "height"
        to: "200"
        duration: 1000
    }
    PropertyAnimation {
        id: animation2
        target: {
            rotation
        }
        properties: "angle"
        to: "72"
        duration: 1000
    }
    PropertyAnimation {
        id: animation3
        target: g1
        properties: "color"
        to: "gray"
        duration: 500
    }
    transform: Rotation {
        id: rotation
        origin.x: 30
        origin.y: 30
        axis {
            x: 1
            y: 0
            z: 0
        }
        angle: 0
    }
    gradient: Gradient {
        GradientStop { id: g1; position: 0.0; color: "blue" }
        GradientStop { id: g2; position: 1.0; color: "blue" }
    }
    states: State{
        name: "moved"; when: mouseArea.entered
        PropertyChanges { target: aaa; width: width+10; height: height+10 }
    }
    transitions: Transition {
        NumberAnimation { properties: "width,height"; duration: 1000 }
    }
}

我试过这两个版本,并简化了一个只有x, y,宽度,高度和颜色属性,没有工作。

解决。我一直在尝试重写核心对象。

相关内容

  • 没有找到相关文章

最新更新