查看完整版本: [-- zhengtianzuo系列-Qml选择开关 --]

QTCN开发网 -> Qt代码秀 -> zhengtianzuo系列-Qml选择开关 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

zhengtianzuo 2017-10-20 14:42

zhengtianzuo系列-Qml选择开关

使用状态来控制开关显示的样式

```
Rectangle {
        id: rect
        width: parent.width * 0.6
        radius: parent.radius
        color: rect.state == "left"? "#4040FF" : "#CCCCCC"
        state: "left"
        anchors {
            top: parent.top
            bottom: parent.bottom
        }

        states: [
            State {
                name: "right"
                PropertyChanges {
                    target: rect
                    x: root.width - rect.width
                }
            }

        ]

        transitions: [
            Transition {
                from: "*"
                to: "*"
                NumberAnimation { property: "x"; duration: 200 }
            }
        ]

        Text {
            id: label
            anchors.centerIn: parent
            text: rect.state == "left"? root.leftString : root.rightString
            color: "white"
            font.pointSize: 10
        }
    }
```



需要完整代码请访问 QtQuickExamples

自强不吸 2017-10-20 14:48
可以鼠标拖动吗

zhengtianzuo 2017-10-20 15:14
自强不吸:可以鼠标拖动吗 (2017-10-20 14:48) 

暂时不行 不过加上也很简单啊


查看完整版本: [-- zhengtianzuo系列-Qml选择开关 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled