qml Text control is designed to display non-editable text, function is quite powerful. Change multiple lines of text, you need to modify WrapMode: Text.WrapAnywhere , Elide: Text.ElideRight , maximumLineCount: 2 to
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 // if cut off text exceeds the display range, default to false . 17 18 is text: " the Hello Wo111111111111111111111 " // text to be displayed . 19 20 is Color: " Red " // text color 21 is 22 is font.family: " Corbel " // Font 23 is 24 font.pixelSize: 25 // set the font size pixel 25 26 is // font.pointSize: 100 // the font size is set to point there pixelSize setting, this setting is invalid 27 28 Font.Bold: to true // italic, bold, defaults to false 29 30 font.capitalization: Font.MixedCase // set the text case, the case is not used, the default value of 31 is 32 // font.capitalization: Font.AllUppercase // all caps 33 is 34 is // font.capitalization: Font.AllLowercase // all lowercase 35 36 // font.capitalization: Font.SmallCaps // lowercase small caps 37 [ 38 is // font.capitalization: Font.Capitalize // The first word of the first character capitalized 39 40 Font.ITALIC: to true // Set italic font style defaults to false 41 is 42 is font.letterSpacing: . 8 // set the distance between letters, in order to increase the number of positive default distance, to reduce the negative 43 is 44 is // font.strikeout: to true // set whether strikeout (middle line), defaults to false 45 46 is font.underline: to true // provided if there decline line, default to false 47 48 @ font.weight: Font.Light 49 50 // font.weight : Font.Normal 51 is 52 is // font.weight: Font.DemiBold 53 is 54 is //font.weight:. Font.Bold 55 56 is @ font.weight: Font.Black 57 is 58 : font.wordSpacing 10 // distance is provided between the word 59 60 @ the horizontalAlignment: Text.AlignRight // Align Right 61 is 62 is // the horizontalAlignment: Text.AlignLeft // left 63 64- // the horizontalAlignment: Text.AlignHCenter // align middle 65 66 the horizontalAlignment: Text.AlignJustify 67 68 // verticalAlignment: Text.AlignTop // aligned in 69 70 the verticalAlignment: Text.AlignBottom // aligned at 71 is 72 @ the verticalAlignment: Text.AlignVCenter // intermediate alignment 73 is 74 Smooth: to true // smooth 75 76 @ style: font style setting Text.Normal 77 78 // style: Text.Outline 79 80 // style: Text.Raised 81 82 // style: Text.Sunken 83 84 styleColor: " Blue" // with the use style 85 86 @ the textFormat: Text.AutoText // text display attributes 87 88 @ the textFormat: Text.PlainText 89 90 @ the textFormat: Text.RichText 91 is 92 @ the textFormat: Text.StyledText 93 94 WrapMode: Text.WrapAnywhere // wrapping property, but needs a clear width of 95 96 // WrapMode: Text.WordWrap // 97 98 // WrapMode: Text.WrapAnywhere 99 100 // WrapMode: Text.Wrap 101 102 Elide: Text.ElideRight // beyond ... instead of using the display range 103 104 // Elide: Text.ElideNone 105 106 // Elide: Text.ElideMiddle 107 108 // Elide: Text.ElideLeft 109 lineHeightMode: Text.FixedHeight // spacing 110 the lineHeight: 20 is 111 maximumLineCount: 2 112 113 onImplicitWidthChanged: { // displayed text itself changes the length of the trigger signal 114 the console.log ( "implicitWidth = ",text_test.implicitWidth) 115 console.log("implicitHeight = ",text_test.implicitHeight) 116 } 117 } 118 }
Renderings: