当前位置:   article > 正文

QML之TabBar_qml tabbar设置宽度后会有一条线

qml tabbar设置宽度后会有一条线

TabBar的切换效果

import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
Window{
    id:window
    visible:true
    width:400
    height:400
    TabBar{
        id:bar;
        width:parent.width;
        TabButton{
            text:qsTr("Home");
        }
        TabButton{
            text:qsTr("Discover");
        }
        TabButton{
            text:qsTr("Activity");
        }
    }
    StackLayout{
        width:parent.width;
        currentIndex:bar.currentIndex;
        Item{
            id:homeTab
        }
        Item{
            id:discoverTab
        }
        Item{
            id:activityTab
        }

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

如果TabBar的宽度超过可用宽度,会自动形成flickable

TabBar{
    id:bar
    width:parent.width
    Repeater{
        model:["First","Second","Third","Fourth","Fifth"]
        TabButton{
            text:modelData;
            width:Math.max(100,bar.width/5);
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

flickable形成的效果是:当点击第4个按钮的时候,第1个按钮隐藏一半,第5个按钮露出一半,当点击第5个按钮的时候,第1个按钮隐藏了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/806065
推荐阅读
相关标签
  

闽ICP备14008679号