本文主要是介绍Qt/QML学习-Dialog,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
QML学习
- Dialog例程
- 视频讲解
- 代码
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15Window {width: 640height: 480visible: truetitle: qsTr("Dialog")Dialog {id: dialoganchors.centerIn: Overlay.overlaytitle: "这里是标题"standardButtons: Dialog.Ok | Dialog.Cancel // 设置标准按钮组合// 头视图header: Text {text: dialog.titlefont.pointSize: 15font.bold: truepadding: 10Rectangle {implicitWidth: parent.widthimplicitHeight: 2anchors.bottom: parent.bottomcolor: "green"}}// 尾视图footer: Text {text: "这里有小尾巴"font.pointSize: 10padding: 10Rectangle {implicitWidth: parent.widthimplicitHeight: 1anchors.top: parent.topcolor: "green"}}// 背景视图background: Rectangle {opacity: 0.3border.width: 1}// 内容视图Rectangle {implicitHeight: 200implicitWidth: 300color: "red"Text {anchors.centerIn: parenttext: "这里是内容"font.pointSize: 30}Button {id: cancelanchors.bottom: parent.bottomanchors.right: parent.righttext: "Cancel"font.pointSize: 20Rectangle {width: 1height: parent.heightanchors.left: parent.left}onClicked: {dialog.rejected()dialog.close()}}Button {id: okanchors.bottom: parent.bottomanchors.right: cancel.lefttext: "Ok"font.pointSize: 20onClicked: {dialog.accepted()dialog.close()}}}// 模态modal: trueonAccepted: {logText.text = "点击了Ok"}onRejected: {logText.text = "点击了Cancel"}}// 添加一个按钮来打开对话框Button {id: buttontext: "打开对话框"anchors.centerIn: parentonClicked: {dialog.open() // 打开对话框}}// 演示用Text {id: logTextanchors.top: button.bottomanchors.horizontalCenter: parent.horizontalCentertopPadding: 10text: "点击结果"font.pointSize: 20}
}
演示
视频讲解
这篇关于Qt/QML学习-Dialog的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!