日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

qml学习笔记(二):可视化元素基类Item详解(上半场anchors等等)

發(fā)布時(shí)間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 qml学习笔记(二):可视化元素基类Item详解(上半场anchors等等) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

原博主博客地址:http://blog.csdn.net/qq21497936
本文章博客地址:http://blog.csdn.net/qq21497936/article/details/78516201

qml學(xué)習(xí)筆記(二):可視化元素基類Item詳解(上半場(chǎng)anchors等等)

? ? 本學(xué)章節(jié)筆記主要詳解Item元素(上半場(chǎng)主要涉及anchors錨),因?yàn)樗锌梢暬慕缑嬖囟祭^承于Item,熟悉Item后,不同的繼承子類,有其定制的屬性(從幾個(gè)到幾十個(gè)不等)。

? ??《Qt實(shí)用技巧:在Qt Gui程序中嵌入qml界面(可動(dòng)態(tài)覆蓋整個(gè)窗口)》:
http://blog.csdn.net/qq21497936/article/details/78486552
? ? 《qml學(xué)習(xí)筆記(一):界面元素初探》:
http://blog.csdn.net/qq21497936/article/details/78498575

? ?《qml學(xué)習(xí)筆記(三):可視化元素基類Item詳解(下半場(chǎng))》
http://blog.csdn.net/qq21497936/article/details/78522816

基類Item介紹

?

??? 基類Item是所有可視化子類的父類,它不是可見的,但是它定義了所有通用元素通用的屬性,比如x、y、width、height、anchoring和handingsuppourt。

? ? 幾個(gè)Item的使用示例? ??

Image示例

?

[css]?view plain?copy
  1. Item{??
  2. ????Rectangle{??
  3. ????????width:1000;??
  4. ????????height:1000;??
  5. ????????color:"black";??
  6. ????????Image?{?//?Image默認(rèn)的背景是透明??
  7. ????????source:"1.png"//?相對(duì)于.qml的路徑??
  8. ????????}??
  9. ????????Image{??
  10. ????????????x:80??
  11. ????????????y:200??
  12. ????????????width:100??
  13. ????????????height:100??
  14. ????????????source:"1.png"??
  15. ????????}??
  16. ????????Image{??
  17. ????????????x:190??
  18. ????????????y:400??
  19. ????????????width:100??
  20. ????????????height:100??
  21. ????????????fillMode:Image.Tile??
  22. ????????????source:"1.png"??
  23. ????????}??
  24. ????}??
  25. }??


? ? 效果如下圖:

?

?

捕捉鍵盤

?

?

[css]?view plain?copy
  1. Item{??
  2. ????focus:true??
  3. ????Keys.onPressed:{??
  4. ????????if(event.key==Qt.Key_Left){??
  5. ????????????console.log("moveleft");??
  6. ????????????event.accepted=true;??
  7. ????????}??
  8. ????}??
  9. ????Keys.onReturnPressed:??
  10. ????????console.log("Pressedreturn");??
  11. }??

?

輸入處理

[css]?view plain?copy
  1. Rectangle{??
  2. width:100;??
  3. height:100??
  4. ????FocusScope{??
  5. ????id:focusScope??
  6. ????focus:true??
  7. ????TextInput{??
  8. ????????id:input??
  9. ????????focus:true??
  10. ????????}??
  11. ????}??
  12. }??

效果如圖

?

屬性詳解

activeFocus?: bool [可讀寫][指示焦點(diǎn):窗口是否獲取焦點(diǎn)]

?

? ? ? ? 此屬性指示元素是否具有活動(dòng)焦點(diǎn)。如果指示是真的,這個(gè)對(duì)象是目前接收鍵盤輸入,或是一個(gè)FocusScope為父對(duì)象的對(duì)象,目前接收鍵盤輸入。

通常,此屬性是通過設(shè)置焦點(diǎn)在其子元素(繼承于Item)和其外圍FocusScope對(duì)象獲得。在下面的例子中,TextInput和FocusScope對(duì)象會(huì)有活躍的熱點(diǎn),而根矩形對(duì)象將不會(huì)。

activeFocusOnTab?: bool [可讀寫][設(shè)置item是否可被tab選中,默認(rèn)為false]

anchors:一組屬性,提供了以元素相互關(guān)系為基準(zhǔn)的定位方式,主要包括以下的:

anchors.top?: AnchorLine [可讀寫][頂部邊界]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:100;??
  5. ????????y:200;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Text?{??
  9. ????????id:?label;??
  10. ????????anchors.top:?pic.bottom;?//?對(duì)象的頂部是與pic的底部高度相同??
  11. ????????text:?"hello?world";??
  12. ????????color:?"black";??
  13. ????????font.pointSize:?14;?//?大于0的值,與設(shè)備無關(guān)font.pixelSize:單位像素,依賴于設(shè)備??
  14. ????}??
  15. }??

anchors.bottom?: AnchorLine [可讀寫][底部邊界]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:100;??
  5. ????????y:200;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Text?{??
  9. ????????id:?label;??
  10. ????????anchors.bottom:?pic.bottom;?//?對(duì)象的頂部是與pic的底部高度相同??
  11. ????????text:?"hello?world";??
  12. ????????color:?"black";??
  13. ????????font.pointSize:?14;?//?大于0的值,與設(shè)備無關(guān)font.pixelSize:單位像素,依賴于設(shè)備??
  14. ????}??
  15. }??

anchors.left?: AnchorLine [可讀寫][左邊界]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:100;??
  5. ????????y:10;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Text?{??
  9. ????????id:?label;??
  10. ????????anchors.left:?pic.right;?//?對(duì)象的頂部是與pic的底部高度相同??
  11. ????????text:?"hello?world";??
  12. ????????color:?"black";??
  13. ????????font.pointSize:?14;?//?大于0的值,與設(shè)備無關(guān)font.pixelSize:單位像素,依賴于設(shè)備??
  14. ????}??
  15. }??

anchors.right?: AnchorLine [可讀寫][右邊界]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:100;??
  5. ????????y:10;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Text?{??
  9. ????????id:?label;??
  10. ????????anchors.right:?pic.right;?//?對(duì)象的頂部是與pic的底部高度相同??
  11. ????????text:?"hello?world";??
  12. ????????color:?"black";??
  13. ????????font.pointSize:?14;?//大于0的值,與設(shè)備無關(guān)font.pixelSize:單位為像素,依賴于設(shè)備??
  14. ????}??
  15. }??

anchors.horizontalCenter?: AnchorLine [可讀寫][水平中心]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????source:?"./1.png";??
  5. ????}??
  6. ????Text?{??
  7. ????????id:?label??
  8. ????????//?對(duì)象的水平中心?以?pic的水平中心?為中心??
  9. ????????anchors.horizontalCenter:?pic.horizontalCenter;??????????
  10. ????????text:?"hello?world";??
  11. ????????color:?"white";??
  12. ????????font.pointSize:?14;?//?大于0的值,與設(shè)備無關(guān)font.pixelSize:單位像素,依賴于設(shè)備??
  13. ????}??
  14. }??

anchors.verticalCenter?: AnchorLine [可讀寫][垂直中心]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:100;??
  5. ????????y:10;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Text?{??
  9. ????????id:?label;??
  10. ????????anchors.verticalCenter:?pic.bottom;?//?對(duì)象的頂部是與pic的底部高度相同??
  11. ????????text:?"hello?world";??
  12. ????????color:?"black";??
  13. ????????font.pointSize:?14;?//大于0的值,與設(shè)備無關(guān)font.pixelSize:單位像素,依賴于設(shè)備??
  14. ????}??
  15. }??

anchors.baseline?: AnchorLine AnchorLine [可讀寫][baseline是指的文本所在的線,如果item沒有文字的話baseline就和top的位置是相同的]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:40;??
  5. ????????y:40;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Text?{??
  9. ????????id:?label;??
  10. ????????anchors.baseline:?pic.top;??
  11. ????????text:?"hello?world";??
  12. ????????color:?"black";??
  13. ????????font.pointSize:?14;?//大于0的值,與設(shè)備無關(guān)font.pixelSize:單位像素,依賴于設(shè)備??
  14. ????}??
  15. }??

anchors.fill?: Item [可讀寫][用本對(duì)象填充指向的對(duì)象元素]

?

[css]?view plain?copy
  1. Item{??
  2. ????Image{??
  3. ????????id:pic;??
  4. ????????x:40;??
  5. ????????y:40;??
  6. ????????source:"./1.png";??
  7. ????}??
  8. ????Rectangle{??
  9. ????????id:label;??
  10. ????????anchors.fill:pic;?//?此時(shí)設(shè)置width和height,測(cè)試無效,直接填滿pic??
  11. ????????color:"black";??
  12. ????}??
  13. }??

?

?

anchors.centerIn?: Item [可讀寫][用本對(duì)象的中心對(duì)準(zhǔn)指向?qū)ο蟮闹行?#xff0c;開始輻射出去,區(qū)域可大于設(shè)置指向的對(duì)象]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:40;??
  5. ????????y:40;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Rectangle?{??
  9. ????????id:?label;??
  10. ????????width:?60;??
  11. ????????height:?60;??
  12. ????????anchors.centerIn:?pic;?//?以pic的中心為該對(duì)象中心進(jìn)行輻射(區(qū)域可大于pic)??
  13. ????????color:?"black";??
  14. ????}??
  15. }??

?

?

anchors.margins?: real [可讀寫][設(shè)置所有(top,bottom,left,right)邊框的寬度]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????x:40;??
  5. ????????y:40;??
  6. ????????source:?"./1.png";??
  7. ????}??
  8. ????Rectangle?{??
  9. ????????id:?label;??
  10. ????????width:?60;??
  11. ????????height:?60;??
  12. ????????color:?"black";??
  13. ????????anchors.margins:?10;??
  14. ????????anchors.left:?pic.right;??
  15. ????}??
  16. ????Rectangle?{??
  17. ????????id:?label2;??
  18. ????????width:?60;??
  19. ????????height:?60;??
  20. ????????color:?"black";??
  21. ????????anchors.margins:?10;??
  22. ????????anchors.top:?pic.bottom;??
  23. ????}??
  24. }??

?

?

[css]?view plain?copy
  1. Item?{??
  2. ????Rectangle?{??
  3. ????????id:?label;??
  4. ????????width:?60;??
  5. ????????height:?60;??
  6. ????????color:?"red";??
  7. ????????anchors.margins:?50;??
  8. ????}??
  9. ????Rectangle?{??
  10. ????????id:?label2;??
  11. ????????width:?60;??
  12. ????????height:?60;??
  13. ????????color:?"black";??
  14. ????????anchors.margins:?50;?//?只對(duì)本對(duì)象設(shè)置anchors邊框有效??
  15. ????????anchors.top:?label.bottom;??
  16. ????}??
  17. ????Rectangle?{??
  18. ????????id:?labe3;??
  19. ????????width:?60;??
  20. ????????height:?60;??
  21. ????????color:?"red";??
  22. ????????anchors.margins:?50;?//?只對(duì)本對(duì)象設(shè)置anchors邊框有效??
  23. ????????anchors.top:?labe2.bottom;??
  24. ????}??
  25. }??

?

?

anchors.topMargin?: real [可讀寫][設(shè)置top邊框的寬度,參照margins]

anchors.bottomMargin?: real [可讀寫][設(shè)置bottom邊框的寬度,參照margins]

anchors.leftMargin?: real [可讀寫][設(shè)置left邊框的寬度,參照margins]

anchors.rightMargin?: real [可讀寫][設(shè)置right邊框的寬度,參照margins]

anchors.horizontalCenterOffset?: real [可讀寫][設(shè)置水平中心偏移量]

[css]?view plain?copy
  1. Item?{??
  2. ????Image?{??
  3. ????????id:?pic;??
  4. ????????source:?"./1.png";??
  5. ????}??
  6. ????Rectangle?{??
  7. ????????width:?30;??
  8. ????????height:?30;??
  9. ????????id:?rect;??
  10. ????????color:?"black";??
  11. ????????//?對(duì)象的水平中心?以?pic的水平中心?為中心??
  12. ????????anchors.horizontalCenter:?pic.horizontalCenter;??
  13. ????????//?注意:horizomtalCenterOffset針對(duì)于horizontalCenter??
  14. ????????anchors.horizontalCenterOffset:?50;??
  15. ????}??
  16. }??

?

?

anchors.verticalCenterOffset?: real [可讀寫][參照設(shè)horizontalCenter,與其類似]

anchors.baselineOffset?: real[可讀寫][參照設(shè)horizontalCenter,與其類似]

anchors.alignWhenCentered?: bool [可讀寫][指定不使用半個(gè)像素繪制圖形,當(dāng)需要居中一個(gè)elements,寬度或者高度是基數(shù),不使用半個(gè)像素繪制,對(duì)此處理解有疑問]

下章節(jié)

《qml學(xué)習(xí)筆記(三):可視化元素基類Item詳解(下半場(chǎng))》:http://blog.csdn.net/qq21497936/article/details/78522816

原博主博客地址:http://blog.csdn.net/qq21497936
本文章博客地址:http://blog.csdn.net/qq21497936/article/details/78516201

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/senior-engineer/p/7986866.html

總結(jié)

以上是生活随笔為你收集整理的qml学习笔记(二):可视化元素基类Item详解(上半场anchors等等)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。