QML之TabWidget

转自:http://blog.csdn.net/liuhongwei123888/article/details/6174839

**
[javascript]**  view plain copy

  1. //TabWidget.qml

  2. import Qt 4.7

  3. Item {

  4. id: tabWidget

  5. default property alias content: stack.children //将tab页集合设置一个默认属性

  6. property int current: 0

  7. onCurrentChanged: setOpacities()

  8. Component.onCompleted: setOpacities()

  9. function setOpacities() {

  10. for(var i = 0; i < content.length; ++i) {

  11. content[i].opacity = (i == current ? 1 : 0);//将当前的tab设置为非透明,其余透明

  12. }

  13. }

  14. Row {  //此组件为tab选项

  15. id: header

  16. Repeater {

  17. model: content.length

  18. delegate: Rectangle {

  19. width: tabWidget.width / content.length

  20. height: 36

  21. color: "#e3e3e3"

  22. Rectangle {  //此组件为tab选项和tab页之间的一条线

  23. width: tabWidget.width; height: 1

  24. anchors { bottom: parent.bottom; bottomMargin: 1}

  25. color: "#abc2c2"

  26. }

  27. BorderImage {  //tab选项图片

  28. anchors { fill: parent; leftMargin: 2; topMargin: 5; rightMargin: 1}

  29. border { left: 7; right: 7}

  30. source: tabWidget.current == index? "tab.png" : "unselect.png"

  31. }

  32. Text {  //tab选项的文本

  33. horizontalAlignment: "AlignHCenter"; verticalAlignment: "AlignVCenter"

  34. anchors.fill: parent

  35. text: content[index].title

  36. elide: Text.ElideRight

  37. font.bold: tabWidget.current == index

  38. }

  39. MouseArea {

  40. anchors.fill: parent

  41. onClicked: tabWidget.current = index  //存储当前选中tab页

  42. }

  43. }

  44. }

  45. }

  46. Item {  //此组件为tab页

  47. id: stack

  48. width: tabWidget.width

  49. anchors.top: header.bottom

  50. anchors.bottom: tabWidget.bottom

  51. }

  52. }

 

[javascript]  view plain copy

  1. //main.qml
  2. import Qt 4.7
  3. TabWidget {
  4. id: tabs
  5. width: 640; height: 480
  6. Rectangle {  //第一个tab页
  7. property  string title: "Red"
  8. anchors.fill: parent
  9. color: "#e3e3e3"
  10. Rectangle {
  11. anchors.fill: parent; anchors.margins: 20 //tab边框与父容器的距离
  12. color: "#7fff7f"
  13. Text {
  14. width: parent.width - 20
  15. anchors.centerIn: parent; horizontalAlignment: "AlignHCenter"
  16. text: "Roses are red"
  17. font.pixelSize: 20
  18. wrapMode: Text.WordWrap
  19. }
  20. }
  21. }
  22. Rectangle { //第二个tab页
  23. property  string title: "Green"
  24. anchors.fill: parent
  25. color: "#e3e3e3"
  26. Rectangle {
  27. anchors.fill: parent; anchors.margins: 20
  28. color: "#7fff7f"
  29. Text {
  30. width: parent.width - 20
  31. anchors.centerIn: parent; horizontalAlignment: "AlignHCenter"
  32. text: "Flower stems are green"
  33. font.pixelSize: 20
  34. wrapMode: Text.WordWrap
  35. }
  36. }
  37. }
  38. Rectangle { //第三个tab页
  39. property  string title: "Blue"
  40. anchors.fill: parent
  41. color: "#e3e3e3"
  42. Rectangle {
  43. anchors.fill: parent; anchors.margins: 20
  44. color: "#7fff7f"
  45. Text {
  46. width: parent.width - 20
  47. anchors.centerIn: parent; horizontalAlignment: "AlignHCenter"
  48. text: "Violets are blue"
  49. font.pixelSize: 20
  50. wrapMode: Text.WordWrap
  51. }
  52. }
  53. }
  54. }

 

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

PPDB:今晚老齐直播

【今晚老齐直播】今晚(本周三晚)20:0021:00小白开始“用”飞桨(https://www.oschina.net/action/visit/ad?id1185)由PPDE(飞桨(https://www.oschina.net/action/visit/ad?id1185)开发者专家计划)成员老齐,为深度学习小白指点迷津。

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )