《QML HelloWorld》學習筆記

原文

http://qt-project.org/doc/qt-4.8/qml-tutorial.html


運行效果


步驟
1、創建QML文件(在QtCreator中根據嚮導創建或者直接用文本文件另存爲)
2、源碼(..\Examples\4.7\declarative\tutorials\helloworld)

import QtQuick 1.0
//![3]
//![1]
Rectangle {
   id: page
   width: 500; height: 200
   color: "lightgray"
//![1]
//![2]
   Text {
       id: helloText
       text: "Hello world!"
       y: 30
       anchors.horizontalCenter: page.horizontalCenter
       font.pointSize: 24; font.bold: true
   }
//![2]
}


3、運行


4、原理

  • Import
  • Rectangle
  • Text
屬性y表示在父元素下多少像素,此處是30像素
屬性anchors.horizontalCenter表示水平居中的位置,此處是頁面中心

發佈了132 篇原創文章 · 獲贊 10 · 訪問量 36萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章