qml⽂本控件和多⾏⽂本显⽰省略号
qml Text控件专门⽤于显⽰⾮编辑⽂本,功能还是⽐较强⼤的。改变多⾏⽂本,需要修改wrapMode:Text.WrapAnywhere,elide: Text.ElideRight,maximumLineCount:2即可
1 import QtQuick 2.9
2 import QtQuick.Window 2.2
3
4 Window {
5 visible: true
6 width: 640
7 height: 480
8 title: qsTr("Hello World")
9 Text{
10 id:text_test
11
12 width: 200
13
14 anchors.horizontalCenter: parent.horizontalCenter
15
16 clip :true//是否剪切掉超出显⽰范围的⽂字,默认false
17
18 text:"Hello Wo111111111111111111111"//需要显⽰的⽂字
19
20 color: "red"//⽂字颜⾊
21
22 font.family: "Corbel"//字体
23
24 font.pixelSize: 25//字体⼤⼩设置为像素
25
26//font.pointSize: 100 //将字体的⼤⼩设置为点,存在pixelSize设置,本设置⽆效
27
28 font.bold: true//是否加粗,默认为false
29
30 font.capitalization: Font.MixedCase //设置⽂本⼤⼩写,不使⽤⼤⼩写,默认值
31
32//font.capitalization: Font.AllUppercase //全部使⽤⼤写
33
34//font.capitalization: Font.AllLowercase //全部使⽤⼩写
35
36//font.capitalization: Font.SmallCaps //⼩写字母使⽤⼩⼤写
37
38//font.capitalization: Font.Capitalize //第⼀个单词第⼀个字符⼤写
39
40 font.italic: true//设置字体是否斜体样式,默认false
41
42 font.letterSpacing: 8//设置字母之间的距离,正数为增加默认距离,负数为减少
43
44//font.strikeout: true //设置是否有删除线(中间⼀条线),默认false
45
46 font.underline: true//设置是否有下滑线,默认false
47
48//font.weight: Font.Light
49
50//font.weight: Font.Normal
51
52//font.weight: Font.DemiBold
53
54//font.weight: Font.Bold
55
56//font.weight: Font.Black
57
58 font.wordSpacing: 10//设置单词之间的距离
59
60//horizontalAlignment: Text.AlignRight //右对齐
61
62//horizontalAlignment: Text.AlignLeft //左对齐
63
64//horizontalAlignment: Text.AlignHCenter //中间对齐
65
66 horizontalAlignment: Text.AlignJustify
67
68//verticalAlignment: Text.AlignTop //上对齐
69
70 verticalAlignment: Text.AlignBottom //下对齐
71
72//verticalAlignment: Text.AlignVCenter //中间对齐
73
74 smooth:true//是平滑
75
textstyle
76//style: Text.Normal 设置字体样式
77
78//style: Text.Outline
79
80// style: Text.Raised
81
82//style: Text.Sunken
83
84 styleColor: "blue"//配合style使⽤
85
86//textFormat: Text.AutoText //⽂本属性显⽰⽅式
87
88//textFormat: Text.PlainText
89
90//textFormat: Text.RichText
91
92//textFormat: Text.StyledText
93
94 wrapMode: Text.WrapAnywhere //换⾏属性设置,但需要明确宽度 95
96// wrapMode: Text.WordWrap //
97
98//wrapMode: Text.WrapAnywhere
99
100//wrapMode: Text.Wrap
101
102 elide: Text.ElideRight //超出显⽰范围的⽤...代替
103
104//elide: Text.ElideNone
105
106//elide: Text.ElideMiddle
107
108// elide: Text.ElideLeft
109 lineHeightMode:Text.FixedHeight //⾏距
110 lineHeight:20
111 maximumLineCount:2
112
113 onImplicitWidthChanged: { //显⽰的⽂本本⾝的长度发⽣变化触发信号114 console.log("implicitWidth = ",text_test.implicitWidth)
115 console.log("implicitHeight = ",text_test.implicitHeight)
116 }
117 }
118 }
效果图:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论