QT开发之QML

1、路径

folder: shortcuts.desktop // 桌面
folder: shortcuts.home
folder: "file:///firmware"//exe所在路径

2、文件对话框

fileDialog.open();//调用


//使用
FileDialog {
            id: fileDialog;
            title: qsTr("Open File");
            folder: shortcuts..desktop // 桌面
            nameFilters: [
                "Files(*.txt)"
            ];
            onAccepted:
            {                
                console.log("You chose: " + fileUrl)
            }
            onRejected:
            {
                console.log("You chose: " + "")
            }
        }

3、控件阴影

import QtGraphicalEffects 1.0





DropShadow {
                    id : shadow2
                    anchors.fill: progressBarBg//为需要增加阴影的控件,阴影大小是按照控件来的
                    horizontalOffset: 1//水平偏移量
                    verticalOffset: 3//垂直偏移量
                    radius: 8.0//指定如何强化阴影接近源 Item 边缘的部分,取值范围为 0.0 -- 1.0 ,默认为 0.5
                    samples: 17//指定生成阴影时阴影的每个像素由多少个采样点产生,采样点越多阴影效果越好,不过也越慢。一般可以把这个值设置为 radius的2倍。
                    color: "#FFFFFF"
                    source: progressBarBg//指向源item,为需要增加阴影的控件
                }

PS:按钮用这个有问题,因为按钮在设置了多种状态后,操作状态会被阴影覆盖掉

进度条例子:

ProgressBar {
            anchors.top: titleText2.Bottom;//进度条顶部在这个控件下面
            id: progressBar
            width: 330
            height: 20
            from: 0
            to: 100
            value: 0           
            anchors.horizontalCenter: parent.horizontalCenter

            background: Rectangle {
                id: progressBarBg
                implicitWidth: parent.width
                implicitHeight: parent.height
                border.width: 2
                border.color: "#FFFFFF"
                color: "transparent"//透明
                radius:10
            }
            contentItem: Item {
                implicitWidth: parent.width
                implicitHeight: parent.height
                Rectangle {
                    radius:10
                    x: progressBarBg.border.width + 1
                    y: progressBarBg.border.width + 1
                    width: progressBar.visualPosition * (parent.width - (progressBarBg.border.width + 1) * 2)
                    height: progressBarBg.implicitHeight - (progressBarBg.border.width + 1) * 2
                    color: "#8183F7"
                }
            }
            DropShadow {
                    id : shadow2
                    anchors.fill: progressBarBg
                    horizontalOffset: 1//右
                    verticalOffset: 3//下
                    radius: 8.0
                    samples: 16
                    color: "#8183F7"
                    source: progressBarBg
                }


        }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值