1.消息提示框


API:
| 属性 | 类型 | 默认值 | 说明 |
| text | string | "" | 对话框文本 |
| duration | int | 1500 | 对话框持续时间 |
| type | string | "" | 对话框类型,值为空使用默认类型, “success”, “error”, “warning”, “info” |
测试代码:
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.15
import "qrc:/components_qml/ShowToast"
ApplicationWindow {
id: mainWindow
width: 1000
height: 700
visible: true
title: "QML消息对话框"
color: "#F5F7FA"
//引用消息对话框
ShowToast {
id: toastDialog
}
// 主界面内容
ColumnLayout {
anchors.centerIn: parent
spacing: 30
Text {
text: "消息对话框演示"
font.pixelSize: 32
font.weight: Font.Bold
color: "#2C3E50"
Layout.alignment: Qt.AlignHCenter
}
// 对话框类型选择
RowLayout {
spacing: 15
Layout.alignment: Qt.AlignHCenter
Rectangle {
width: 10
height: 10
radius: 5
color: "#3498DB"
}
Text {
text: "选择对话框类型:"
font.pixelSize: 18
color: "#34495E"
}
}
// 按钮区域
GridLayout {
columns: 3
columnSpacing: 20
rowSpacing: 20
Layout.alignment: Qt.AlignHCenter
// 基础对话框
DialogButton {
text: "基础对话框"
bgColor: "#3498DB"
onClicked: {
toastDialog.text = "这是一个字符串";
toastDialog.show();
}
}
DialogButton {
text: "成功对话框"
bgColor: "#2ECC71"
onClicked: {
toastDialog.text = "操作成功!";
toastDialog.type = "success";
toastDialog.show();
}
}
DialogButton {
text: "错误对话框"
bgColor: "#E74C3C"
onClicked: {
toastDialog.text = "操作失败,请重试!";
toastDialog.type = "error";
toastDialog.show();
}
}
DialogButton {
text: "警告对话框"
bgColor: "#F39C12"
onClicked: {
toastDialog.text = "警告:资源不足";
toastDialog.type = "warning";
toastDialog.show();
}
}
DialogButton {
text: "信息对话框"
bgColor: "#3498DB"
onClicked: {
toastDialog.text = "您有3条新消息";
toastDialog.type = "info";
toastDialog.show();
}
}
}
}
// 对话框按钮组件
component DialogButton: Rectangle {
property alias text: buttonText.text
property alias icon: iconImage.source
property alias bg

最低0.47元/天 解锁文章
1888

被折叠的 条评论
为什么被折叠?



