新聞中心
? QML是Qt推出的Qt Quick技術(shù)的一部分,是它新增的簡便易學(xué)的語言。
? QML是一種描述性語言,用來描述一個(gè)程序的用戶界面:是什么樣子,以及它如何表現(xiàn)。
? 在QML中,一個(gè)用戶界面被指定為具有屬性的對(duì)象樹。 這使得Qt更加便于很少或沒有編程經(jīng)驗(yàn)的人使用。
? QML是Qt4.7.0中新增的Qt Quick核心組件:它是一個(gè)標(biāo)識(shí)語言,由QtQuick封裝在Item {}的元素的標(biāo)識(shí)組成。 它從頭設(shè)計(jì)了用戶界面的創(chuàng)建, 可以讓開發(fā)人員快速、?簡單的理解。 用戶界面可以使用JavaScript代碼來提供和加強(qiáng)更多的功能。 Qt Quick可以使用本地已有的Qt C++輕松快速的擴(kuò)展它的能力。 簡單聲明的UI被稱作前端, 本地部分被稱作后端。 這樣可將程序的計(jì)算密集部分與來自應(yīng)用程序用戶界面操作部分分開。
? 在項(xiàng)目中前端開發(fā)使用QML/JaveScript, 后端代碼開發(fā)使用Qt C++來完成系統(tǒng)接口和計(jì)算工作,能自然地將設(shè)計(jì)界面的開發(fā)者和功能開發(fā)者分開。
? 創(chuàng)建一個(gè)簡單的HelloWorld,在QtCreator中可以一步一步實(shí)現(xiàn),可參考網(wǎng)上相關(guān)步驟,代碼如下:
import QtQuick 2.12
Rectangle {
id: myRectangle;
width: 360; height: 360;
color: "lightgray";
Text {
text: "Hello World"; color: "darkgreen";
x: 100; y:100;
anchors.centerIn: parent;
}
}
import QtQuick 2.12
Rectangle {
id: myRectangle;
width: 360; height: 360;
color: "lightgray";
Text {
text: "Hello World"; color: "darkgreen";
x: 100; y:100;
anchors.centerIn: parent;
}
}
這里需要重點(diǎn)提要的知識(shí)點(diǎn)是Item對(duì)象和anchors:
Item
- Item 類型是 Qt Quick 中所有可視項(xiàng)的基本類型;
- Qt Quick 中的所有可視項(xiàng)都繼承自 Item,注意?Item 對(duì)象沒有視覺外觀,但它定義了所有視覺項(xiàng)的通用屬性。
- Item 類型可做為根元素包含視覺項(xiàng)目。
anchors
Item的anchors屬性包含以下情況:
// 4個(gè)邊:
anchors.top : AnchorLine
anchors.bottom : AnchorLine
anchors.left : AnchorLine
anchors.right : AnchorLine
// 2個(gè)居中
anchors.horizontalCenter : AnchorLine
anchors.verticalCenter : AnchorLine
//?基線
anchors.baseline : AnchorLine
//?填充與居中
anchors.fill : Item
anchors.centerIn : Item
// 1+4個(gè)邊界
anchors.margins : real
anchors.topMargin : real
anchors.bottomMargin : real
anchors.leftMargin : real
anchors.rightMargin : real
// 2個(gè)居中的偏移值+基線的偏移值
anchors.horizontalCenterOffset : real
anchors.verticalCenterOffset : real
anchors.baselineOffset : real
//?居中時(shí)對(duì)齊屬性? ? ? ? ? 強(qiáng)制居中,默認(rèn)為true, 假如寬或者高為奇數(shù)時(shí),如果中心對(duì)齊, 就可以保證絕對(duì)對(duì)齊。
anchors.alignWhenCentered : bool
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
分享題目:01第一個(gè)Qml程序例子引出的相關(guān)知識(shí)點(diǎn)-創(chuàng)新互聯(lián)
分享鏈接:http://www.ef60e0e.cn/article/ehoeo.html