1、Item
所有的QML可視化元素都繼承自Item,。Item沒(méi)有可視化界面,,但是它定義了可視化元素的所有屬性。
- import Qt 4.7
- Item{
- width: 500;height: 400
- Image{
- source: "images/qt.png"
- }
- Image {
- x: 80
- y: 100
- source: "images/qt.png"
- }
- Image {
- x: 190
- width: 100;height: 100
- fillMode: Image.Tile
- source: "images/qt.png"
- }
- }
- //記住要為Item指定width和height不然運(yùn)行看不到窗體
按鍵事件:
- Item {
- width: 200; height: 100
- focus: true
- Keys.onPressed: {
- console.log(event.key);
- console.log(Qt.Key_Left);
- if(event.key == Qt.Key_Left){
- console.log("move left");//控制臺(tái)打印信息
- event.accepted = true;
- }
- }
- Keys.onSelectPressed: console.log("Selected");
- Keys.onDigit0Pressed: console.log("0 Pressed");
- }
- //Keys事件還有很多具體可以查API,,onSelectPressed,,我現(xiàn)在也不知道怎么觸發(fā),希望有朋友知道告訴我,。
Item以及繼承自它的元素的大多數(shù)屬性,,當(dāng)屬性值變化會(huì)有一個(gè)信號(hào)發(fā)射出去。
2,、Rectangle
- Rectangle {
- width: 100
- height: 100
- color: "white"
- border.color: "#FF12FF"
- border.width: 10
- radius: 10
- Rectangle {
- anchors.fill :parent
- anchors.margins: 10
- color: "red"
- clip: true
- Rectangle {
- anchors.fill: parent
- border.width: 1
- }
- }
- }
- //注:color的值不能用16進(jìn)制0x******表示
- Rectangle{
- width: 400; height: 300
- Rectangle {
- width: 80; height: 80
- color: "lightsteelblue"
- radius: 8
- }
- Rectangle {
- y: 100; width: 80; height: 80
- gradient: Gradient {
- GradientStop {position: 0.0; color: "lightsteelblue"}
- GradientStop {position: 1.0; color: "blue"}
- }
- radius: 8
- }
- Rectangle {
- y: 200; width: 80; height: 80
- rotation: 90
- gradient: Gradient {
- GradientStop { position: 0.0; color: "lightsteelblue" }
- GradientStop { position: 1.0; color: "blue" }
- }
- radius: 8
- }
- }
Gradient顧名思義,,即梯度,也就是我們常說(shuō)的逐變色,。一個(gè)gradient 被兩個(gè)或更多的顏色定義混合形成,。顏色可以從位置0.0到1.0逐漸變化,,如:
- Rectangle {
- width: 100; height: 100
- gradient: Gradient {
- GradientStop { position: 0.0; color: "red" }
- GradientStop { position: 0.33; color: "yellow" }
- GradientStop { position: 1.0; color: "green" }
- }
- }
Gradient包含一個(gè)屬性:stops:list<GradientStop>
GradientStop元素僅包含兩個(gè)屬性color:color和position:real
3,、AnimatedImage
此元素是用于播放動(dòng)畫(huà)像gif這樣存儲(chǔ)著幀的文件
- import Qt 4.7
- Rectangle {
- width: animation.width; height: animation.height + 8
- AnimatedImage { id: animation; source: "animation.gif" }
- Rectangle {
- property int frames: animation.frameCount
- width: 4; height: 8
- x: (animation.width - width) * animation.currentFrame / frames
- y: animation.height
- color: "red"
- }
- }
4、TextInput
做過(guò)界面開(kāi)發(fā)的應(yīng)該都知道這就是個(gè)單行文本框.它有很多豐富的屬性
- TextInput {
- id: textInput
- text: "Hello world!"
- width: 200;
- height: 20;
- activeFocusOnPress: false
- selectionColor: "#00FF00"
- selectByMouse: true
- echoMode: TextInput.Password
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if (!textInput.activeFocus) {
- textInput.forceActiveFocus()
- textInput.openSoftwareInputPanel();
- } else {
- textInput.focus = false;
- }
- }
- onPressAndHold: textInput.closeSoftwareInputPanel();
- }
- }
5,、TextEdit
多行文本框.
6,、Image
上面已用到過(guò)了,就是普通顯示圖片的元素
7,、Text
通常就是用作一個(gè)標(biāo)簽,,在界面上顯示信息.
8、BorderImage
用來(lái)做窗口的邊界,。
http://www./?p=592 介紹的很詳細(xì),。哈哈。謝謝這個(gè)網(wǎng)站,,我在里面學(xué)了很多qt相關(guān)的知識(shí)
9,、除了上面介紹這些之外QML還提供了三個(gè)驗(yàn)證器,分別是IntValidator,DoubleValidator,RegExpValidator
|