Qml-TabBar类使用

打印 上一主题 下一主题

主题 1043|帖子 1043|积分 3129

Qml-TabBar类使用

TabBar的概述


  • TabBar继承于Container 由TabButton举行添补,可以与提供currentIndex属性的任何容器或布局控件一起使用,如StackLayout 或 SwipeView;
  • contentHeight : real:TabBar的内容高度,用于计算标签栏的隐式高度
  • contentWidth : real:TabBar的内容宽度,用于计算标签栏的隐式宽度
  • position : enumeration:假如TabBar用于Application或Page 组件,TabBar的位置
SplitView的实例代码

  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. //TabBar继承于Container, 由TabButton填充,可于提供currentIndex属性的容器或者布局器使用,如StackLayout 或 SwipeView
  5. Item {
  6.     id: idTabBarRoot
  7.     Rectangle{
  8.         anchors.fill: parent
  9.         TabBar{
  10.             id:idTabBar
  11.             //指明TabBar的高度和宽度
  12.             contentHeight: 40
  13.             contentWidth: parent.width
  14.             //如果没有明确宽度,TabButton会均分或者由TabButton的隐式宽度的和来推导TabBar的宽度
  15.             TabButton{
  16.                 text: ("Tab1")
  17.                 //width: 100
  18.                 implicitWidth: 100
  19.                 onClicked: {
  20.                     console.log("tabButton index = ",TabBar.index);
  21.                 }
  22.             }
  23.             TabButton{
  24.                 //width: 100
  25.                 implicitWidth: 100
  26.                 text: ("Tab2")
  27.             }
  28.             TabButton{
  29.                 //width: 100
  30.                 implicitWidth: 100
  31.                 text: ("Tab3")
  32.             }
  33.             onCurrentIndexChanged: {
  34.                 console.log("cur index = ",idTabBar.currentIndex,"contentWidth = ",idTabBar.contentWidth);
  35.                 console.log("conttentHeight = ",idTabBar.contentHeight)
  36.                 var child = idTabBar.contentChildren;               //返回一个list 数据
  37.                 console.log("child size = ",child.length);          //可以使用list 的length属性获取 list的长度
  38.             }
  39.             background:Rectangle{
  40.                 anchors.fill: parent;
  41.                 color:"yellow"
  42.                 border.width:1
  43.                 border.color: "red";
  44.             }
  45.         }
  46.         //栈布局,只显示currentIndex对应的Item
  47.         StackLayout{
  48.             //需要在StackLayout中做布局,控制StackLayout的区域
  49.             anchors.top: idTabBar.bottom
  50.             anchors.bottom: parent.bottom
  51.             width: parent.width
  52.             currentIndex: idTabBar.currentIndex
  53.             //插入于TabBar 中TabButton 对应的内容区域
  54.             Text{
  55.                 text: "I am Tab1 "
  56.                 verticalAlignment: Text.AlignVCenter
  57.                 horizontalAlignment: Text.AlignHCenter;
  58.             }
  59.             Text{
  60.                 text: "I am Tab2 "
  61.                 verticalAlignment: Text.AlignVCenter
  62.                 horizontalAlignment: Text.AlignHCenter;
  63.             }
  64.             Text{
  65.                 text: "I am Tab3 "
  66.                 verticalAlignment: Text.AlignVCenter
  67.                 horizontalAlignment: Text.AlignHCenter;
  68.             }
  69.         }
  70.     }
  71. }
复制代码
TabBar实例代码运行结果如下:



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

麻花痒

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表