首页 > 编程知识 正文

qt密码输入框,qt 自定义的类如何显示

时间:2023-05-06 20:24:34 阅读:43841 作者:4269

这是符合CC 4.0 BY-SA版权协议的博主的原创文章。 请附上原文来源的链接和本声明。

本文链接: https://blog.csdn.net/a 844651990/article/details/78376767

Qt qml自定义消息提示框

QtQuick有一个比较传统的信息提示框消息诊断程序,但实际开发过程并非如此

能满足我们的需要。 以下是根据控制2模块中的诊断控件定制的简单信息提示框。

可以根据信息量自动调整信息框的大小。

以下代码:

1

MsgDialog.qml

导入Qt quick 2.6

导入Qt quick.window 2.2

import QtQuick.Controls 2.2

import QtQuick.Layouts 1.3

Item {

id:路由

anchors.centerIn: parent

//提示框的内容

propertyaliastiptext : msg.text

//提示框颜色

propertystringbackgroundcolor : ' white '

propertyitemparentitem 3360 rectangle { }

//Dialog header、contentItem和footer之间的间距默认为12

//提示框的最小宽度为100

width: {

if (msg.implicit width 100|| msg.implicit width==100 )

返回100

else

return msg.implicitWidth 300? 30024:(msg.implicitwidth24 );

}

height : msg.implicit height 24100

诊断程序{

id :诊断程序

width:根. width

height: root.height

modal :真

后台: rectangle {

color :背景色

anchors.fill: parent

radius: 5

}

header: Rectangle {

width: dialog.width

高海拔: 50

border.color : background color

radius: 5

Image {

width: 40

高清: 40

anchors.centerIn: parent

source : '/images/warning _ 48.png '

}

}

contentitem :恢复

border.color : background color

color :背景色

文本{

anchors.fill: parent

anchors.centerIn: parent

font.family : ' microsoftyahei '

color: 'gray '

text: tipText

wrapMode: Text.WordWrap

垂直对齐3360 text.align vcenter

horizontal alignment 3360 text.alignhcenter

}

}

footer: Rectangle {

width: msg.width

高海拔: 50

border.color : background color

color :背景色

radius: 5

Button {

anchors.centerIn: parent

width: 80

高清: 30

后台: rectangle {

anchors.centerIn: parent

width: 80

高清: 30

radius: 5

border.color: '#0f748b '

border.width: 2

color :背景色

文本{

anchors.centerIn: parent

font.family : ' microsoftyahei '

font.bold: true

color: '#0f748b '

text: 'OK '

}

}

onClicked: {

dialog.close (;

}

}

}

}

使用Text的implicitWidth属性调整提示框的大小

//此文本的字体格式必须与contentItem的字体一模一样

文本{

id: msg

visible :假

width: 300

wrapMode: Text.WordWrap

font.family : ' microsoftyahei '

垂直对齐3360 text.align vcenter

horizontal alignment 3360 text.alignhcenter

}

功能打开msg (

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,则显示“objectdestroyedduringing 目前找不到解决方案。

注意:作者使用的是Qt5.9版本。 文章中使用的一些属性是从Qt5.8开始的。

下载源代码: http://download.csdn.net/download/a 844651990/10042941

————————————————

这是CSDN博客“FlyWM_”的原始文章,符合CC 4.0 BY-SA版权协议。 请附上原文来源的链接和本声明。

原文链接: https://blog.csdn.net/a 844651990/article/details/78376767

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。