【qml】在qml中自定义对话框

MyDialog.qml内容如下:

import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2


Window {
    id: root
    width: 300
    height: 100
    flags: Qt.Popup
    modality: Qt.ApplicationModal
    x: Screen.width/2-width/2
    y: Screen.height/2-height/2

    Column{
        anchors.fill: parent
        Rectangle{
            width: parent.width
            height: 30
            color: "silver"
            Text{
                width: contentWidth
                height: parent.height
                text: "信息提示"
            }

            Button{
                anchors.right: parent.right
                height: parent.height
                width: height

            }
        }
        Rectangle{
            width: parent.width
            height: 200
            color: "green"
            Text{
                width: parent.width
                anchors.centerIn: parent
                text: "PPPP"
                font.pixelSize: 27
                focus: true
                wrapMode: Text.Wrap
            }
        }
        Rectangle{
            width: parent.width
            height: 30
            color: "silver"
            Button{
                DebugRect{}

                id: btnOk
                focus: true
                width: 100
                height: parent.height
                anchors.centerIn: parent
                onClicked: {
                    root.hide();
                }
                Keys.onReturnPressed: {
                    root.hide();
                }
            }
        }
    }

    onActiveChanged: {
        if(active == true)
        {
            btnOk.forceActiveFocus();
        }
    }
}

main.qml中打开对话框的代码如下:

        Button{
            DebugRect{}
            width: 100
            height: 50
            focus: true
            activeFocusOnPress: true

            Keys.onReturnPressed: {
                dialog.show();
                dialog.requestActivate();
            }
        }

        MyDialog{
            id: dialog
            width: 500
            height: 400
            visible: false
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

草丛中的蝈蝈

您的鼓励是我最大的动力....

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值