让我来发布一点答辩(是真的写的很答辩的QML控件)

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.0

Item {
    id: combolBox

    property int btn_x: 0
    property int btn_y: 0
    property int btn_width: 80
    property int btn_height: 20
    property var btn_color: "#EEEEEE"
    property var btn_hover_color: "gray"
    property var btn_img_source: null
    property int btn_radius: 10
    property string btn_text: "btn_text"

    property int box_num: 10
    property int box_width: 200
    property int box_height: 20
    property var box_texts: ["box1", "box2","box3"]

    property bool combolBox_open: false

    Rectangle{
        id: combolBox_btn

        x: btn_x; y: btn_y
        width: btn_width; height: btn_height
        color: btn_color

        radius: btn_radius

        Label {
            id: combolBox_btn_label

            anchors.fill: parent

            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter

            text: qsTr(btn_text)
        }

        Image {
            id: btn_img
            anchors.fill:parent
            source: btn_img_source
        }

        MouseArea{
            hoverEnabled: true

            anchors.fill: parent

            onEntered: {
                parent.color = btn_hover_color
            }

            onExited: {
                parent.color = btn_color
            }

            onClicked: {
                combolBox_open = !combolBox_open
            }
        }

    }

    Rectangle{
        id: outer_container

        state: combolBox_open ? "open" : "closed"

        color: "#00000000"

        states: [
            State {
                name: "closed"
                PropertyChanges {
                    target: outer_container

                    x: btn_x; y: btn_y + btn_height
                    width: 0; height: 0
                }
            },

            State {
                name: "open"
                PropertyChanges {
                    target: outer_container

                    x: btn_x + 10; y: btn_y + btn_height + 5
                    width: box_width + 11; height: box_height*box_num + 11
                }
            }
        ]

        transitions: [
            Transition {
                from: "closed"
                to: "open"

                NumberAnimation{
                    properties: "x, y, width, height"

                    duration: 30
                }
            },

            Transition {
                from: "open"
                to: "closed"

                NumberAnimation{
                    properties: "x, y, width, height"

                    duration: 30
                }
            }
        ]

        Rectangle{
            id:container

            anchors.top: parent.top
            anchors.left: parent.left
            width: parent.width - 5; height: parent.height - 5

            radius: 10

            Rectangle{
                id: hover_highlighter

                x: parent.x + 3
                width: combolBox_open ? box_width : 0
                height: combolBox_open ? box_height : 0
                z: 0
                color: "gray"

                Behavior on y{
                    NumberAnimation{
                        duration: 50
                    }
                }

                radius: 5
            }

            Repeater{
                model: box_num

                Rectangle{
                    color: "#00000000"
                    width: box_width; height: box_height
                    y: box_height * index + 3

                    Label{
                        z: 1
                        visible: combolBox_open ? true : false

                        anchors.fill: parent
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignVCenter

                        text: index
                    }

                    MouseArea{
                        anchors.fill: parent
                        hoverEnabled: true

                        onEntered: {
                            hover_highlighter.y = parent.y
                        }
                    }
                }
            }
        }

        DropShadow{
            id: container_shadow

            source: container
            anchors.fill: container

            horizontalOffset: 5
            verticalOffset:  5

            samples: 18

            radius: 10
        }
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值