qml 自定义消息框_Qt qml 自定义消息提示框
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/a844651990/article/details/78376767
Qt qml 自定义消息提示框
QtQuick有提供比较传统的信息提示框MessageDialog,但是实际开发过程并不
太能满足我们的需求。下面是根据controls2模块中Dialog控件自定义的简单的信息提示框。
可以根据信息的多少来自动调节信息框的大小:
下面上代码:
1
MsgDialog.qml
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
Item {
id: root
anchors.centerIn: parent
//提示框内容
property alias tipText: msg.text
//提示框颜色
property string backGroundColor: "white"
property Item parentItem : Rectangle {}
//Dialog header、contentItem、footer之间的间隔默认是12
// 提示框的最小宽度是 100
width: {
if(msg.implicitWidth < 100 || msg.implicitWidth == 100)
return 100;
else
return msg.implicitWidth > 300 ? 300 + 24 : (msg.implicitWidth + 24);
}
height: msg.implicitHeight + 24 + 100
Dialog {
id: dialog
width: root.width
height: root.height
modal: true
background: Rectangle {
color: backGroundColor
anchors.fill: parent
radius: 5
}
header: Rectangle {
width: dialog.width
height: 50
border.color: backGroundColor
radius: 5
Image {
width: 40
height: 40
anchors.centerIn: parent
source: "/images/warning_48.png"
}
}
contentItem: Rectangle {
border.color: backGroundColor
color: backGroundColor
Text {
anchors.fill: parent
anchors.centerIn: parent
font.family: "Microsoft Yahei"
color: "gray"
text: tipText
wrapMode: Text.WordWrap
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
footer: Rectangle {
width: msg.width
height: 50
border.color: backGroundColor
color: backGroundColor
radius: 5
Button {
anchors.centerIn: parent
width: 80
height: 30
background: Rectangle {
anchors.centerIn: parent
width: 80
height: 30
radius: 5
border.color: "#0f748b"
border.width: 2
color: backGroundColor
Text {
anchors.centerIn: parent
font.family: "Microsoft Yahei"
font.bold: true
color: "#0f748b"
text: "OK"
}
}
onClicked: {
dialog.close();
}
}
}
}
//利用Text 的implicitWidth属性来调节提示框的大小
//该Text的字体格式需要与contentItem中的字体一模一样
Text {
id: msg
visible: false
width: 300
wrapMode: Text.WordWrap
font.family: "Microsoft Yahei"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
function openMsg() {
root.x = (parent.width - dialog.width) * 0.5
root.y = (parent.height - dialog.height) * 0.5
dialog.open();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
在做这个控件的时候发现了一个问题,就是当我们利用Loader加载控件并且该控件使用了controls2模块时,把loader的asynchronous属性设置为true的时候,会报错”Object destroyed during incubation”,目前还没有找到解决的办法,有知道的同学可以交流一下。。。。
注意:作者使用的是Qt5.9版本,文章中使用的有些属性是从Qt5.8才开始有的!
源码下载: http://download.csdn.net/download/a844651990/10042941
————————————————
版权声明:本文为CSDN博主「FlyWM_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/a844651990/article/details/78376767
qml 自定义消息框_Qt qml 自定义消息提示框相关推荐
- php js对话框,JavaScript_js弹出框、对话框、提示框、弹窗实现方法总结(推荐),一、JS的三种最常见的对话框- phpStudy...
js弹出框.对话框.提示框.弹窗实现方法总结(推荐) 一.JS的三种最常见的对话框 //====================== JS最常用三种弹出对话框 ==================== ...
- js弹出框、对话框、提示框、弹窗总结
一.JS的三种最常见的对话框 //====================== JS最常用三种弹出对话框 ========================//弹出对话框并输出一段提示信息functio ...
- JavaScript弹出框、对话框、提示框、弹窗总结
JavaScript弹出框.对话框.提示框.弹窗总结. 1.JS的三种最常见的对话框 //====================== JS最常用三种弹出对话框 =================== ...
- Jquery提示框效果(确认提示框)
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8" ...
- php点击文字弹出js提示框,js弹出框、对话框、提示框、弹窗实现方法总结(推荐)...
一.JS的三种最常见的对话框 //====================== JS最常用三种弹出对话框 ======================== //弹出对话框并输出一段提示信息 funct ...
- 弹出框之对话框和提示框,可共用代码
弹出框: //对话框,title是标题文字,content是提示框内容,test是一个function(点击确定按钮触发的事件) function dialogBox(title,content,te ...
- 如何在html上做弹框效果,网页|利用提示框(Tooltip)实现弹窗效果
一.提示框的运用 二.Tooltip简单介绍 提示工具(Tooltip)是一个插件,可以根据需求生成标记内容,但在默认情况下是把提示工具(tooltip)放在它们的触发元素后面.在bootstrap中 ...
- 自定义弹框,点击提示框外空白区域,让弹框消失
tip: self.mainView 是提示框的全屏背景.一般是透明的黑色 self.bgImg 添加提示内容的主要view 方法一:正常情况下,各个页面都有touchesBegan:withE ...
- ant-design中Input输入框在获取焦点时由于保留了上次输入内容而莫名出现了一个黑色背景的选择提示框,且选择提示框中的值后还会出现蓝色背景
一. 代码环境 "react": "18.1.0", "antd": "^4.20.5", "typescri ...
最新文章
- Java字符串格式化
- Java设计模式——装饰者模式
- Git本地分支和远程分支关联
- oracle行列转换关联union的方式_几行代码轻松玩转 Excel 行列转换
- 一次使用duplicate创建测试数据库的过程
- android升级adt和sdk之后无法识别SDK Location的一个解决方式
- linux mysql 密码策略_linux密码策略
- 图文并茂地带你了解kafka分区Rebalance机制
- switch常用的交换机配置命令
- django 序列化组件Serializer
- 1013_MISRA C规范学习笔记9
- masm32踩坑总结
- java 2的n次方_Java程序练习-计算2的N次方 | 学步园
- 正确设置路由器时间和时区
- ld cannot find -lbz2
- 阿里设计师:B端产品国际版体验设计
- base上海 Ai建筑设计 Python招聘ing
- ubuntu下查看电脑内存硬盘CPU显卡驱动等配置命令
- Norm(范式)的讲解
- 英语月份、星期、日期的缩写