QML::Text/TextEdit


 

 

  //定義一個文本,寫法1
   Text {
       id: t1
       text: qsTr("text")
       font.pixelSize: 50
       font.bold: true
       font.pointSize: 1
   }

   //定義一個文本,寫法2
   Text {
       id: t2
       text: qsTr("text2")
       font{pixelSize: 30; bold:true}
   }
    
    //定義一個文本
    Text {
        width: 200; height: 200
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        text: "中心"
        color: "red"
    }

 

Text {
        width: 200;
        text: "使文本在單行中對於超出部分不要進行省略"
    }
    Text {
        width: 200; elide: Text.ElideLeft;
        text: "使文本在單行中對於超出部分從左邊進行省略"
    }
    Text {
        width: 200; elide: Text.ElideMiddle;
        text: "使文本在單行中對於超出部分從中間進行省略"
    }
    Text {
        width: 200; elide: Text.ElideRight;
        text: "使文本在單行中對於超出部分從右邊進行省略"
    }

 

 Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" }
 Text { text: "<b>Hello</b> <i>World!</i>" }
 Text { x:10; y:100; font.pointSize: 24; text: "Normal" }
 Text { x:10; y:200; font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" }
 Text { x:10; y:300; font.pointSize: 24; text: "Outline";style: Text.Outline; styleColor: "red" }
 Text { x:10; y:400; font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" }

 

 //超鏈接
Text { textFormat: Text.RichText text: "The main website is at <a href=\"http://qt.nokia.com\">Nokia Qt DF</a>." onLinkActivated: console.log(link + " link activated") }

 

 

 

TextEdit顯示一個可編輯的,有格式的文本框。它也可以顯示明文和富文本。

    //富文本
    Flickable {//套一個Flickable使其具有滑動效果。
        id: flick
        width: 300; height: 200;
        contentWidth: edit.paintedWidth
        contentHeight: edit.paintedHeight
        clip: true

        function ensureVisible(r)
        {
            if (contentX >= r.x)
                contentX = r.x;
            else if (contentX+width <= r.x+r.width)
                contentX = r.x+r.width-width;
            if (contentY >= r.y)
                contentY = r.y;
            else if (contentY+height <= r.y+r.height)
                contentY = r.y+r.height-height;
        }

        TextEdit {
            id: edit
            width: flick.width
            height: flick.height
            focus: true
            wrapMode: TextEdit.Wrap //不在一行,多行顯示
            onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM