封装QML常见控件使用方法

main.qml 

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.14

//使用qml常用的控件
/*
    Text
    Button
    ToolTip
    ComboBox
    ...(更新中)
*/
Window
{
    //定义变量
    property bool tip_visible: false

    visible: true
    width: 450
    height: 400
    id:rect
    title: "qml控件"  //界面标题
    Text
    {
        id: _text
        width: 100
        height: 30
        anchors.left: parent    //父部件左边
        leftPadding: 30         //距离左边30个像素点
        topPadding: 30          //距离顶部30个像素点
        text: qsTr("学习使用qml控件")
        color: "blue"
    }

    Column  //一列
    {
        spacing: 30 //列间隔
        leftPadding: 30
        x:_text.x       //这里使用坐标
        y:_text.y+60
        ComboBox
        {
            id:combox

            width:200
            height: 60

            displayText: "cur: " + currentText
            model : ['a','b','c']

            delegate: ItemDelegate
            {
                height:30
                width:parent.width
                Text
                {
                    id:combox_text
                    text:modelData
                    color:"black"
                }
            }
        }

        Button  //按钮
        {
            id:btn
            height: 60
            width: 200
            text: "按钮"
            ToolTip //提示
            {
                text: "点击我退出"
                visible: tip_visible
                delay:1000
                timeout:2000
                font    //字体
                {
                    pixelSize:30
                    family:"微软雅黑"
                }
            }
            background:Rectangle
            {
                color:Qt.darker("yellow")
            }

            MouseArea   //鼠标
            {
                id:mouseArea
                anchors.fill: parent
                hoverEnabled: true
                onEntered:  //鼠标进入
                {
                    console.log("mouse enter")  //打印日志
                    if(tip_visible===false)
                    {
                        tip_visible = true
                    }
                }
                onExited:   //鼠标离开
                {
                    if(tip_visible===true)
                    {
                        tip_visible = false
                    }
                }
                onClicked:  //鼠标按下
                {
                    Qt.quit()                
                }
            }
        }
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值