examples/declarative/ui-components/tabwidget/TabWidget.qml
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    41 import Qt 4.7
    41 import Qt 4.7
    42 
    42 
    43 Item {
    43 Item {
    44     id: tabWidget
    44     id: tabWidget
    45 
    45 
       
    46     // Setting the default property to stack.children means any child items
       
    47     // of the TabWidget are actually added to the 'stack' item's children.
       
    48     // See the "Extending Types from QML" documentation for details on default
       
    49     // properties.
       
    50     default property alias content: stack.children
       
    51 
    46     property int current: 0
    52     property int current: 0
    47     default property alias content: stack.children
       
    48 
    53 
    49     onCurrentChanged: setOpacities()
    54     onCurrentChanged: setOpacities()
    50     Component.onCompleted: setOpacities()
    55     Component.onCompleted: setOpacities()
    51 
    56 
    52     function setOpacities()
    57     function setOpacities() {
    53     {
       
    54         for (var i = 0; i < stack.children.length; ++i) {
    58         for (var i = 0; i < stack.children.length; ++i) {
    55             stack.children[i].opacity = i == current ? 1 : 0
    59             stack.children[i].opacity = (i == current ? 1 : 0)
    56         }
    60         }
    57     }
    61     }
    58 
    62 
    59     Row {
    63     Row {
    60         id: header
    64         id: header
       
    65 
    61         Repeater {
    66         Repeater {
       
    67             model: stack.children.length
    62             delegate: Rectangle {
    68             delegate: Rectangle {
    63                 width: tabWidget.width / stack.children.length; height: 36
    69                 width: tabWidget.width / stack.children.length; height: 36
    64 
    70 
    65                 Rectangle {
    71                 Rectangle {
    66                     width: parent.width; height: 1
    72                     width: parent.width; height: 1
    83                 MouseArea {
    89                 MouseArea {
    84                     anchors.fill: parent
    90                     anchors.fill: parent
    85                     onClicked: tabWidget.current = index
    91                     onClicked: tabWidget.current = index
    86                 }
    92                 }
    87             }
    93             }
    88             model: stack.children.length
       
    89         }
    94         }
    90     }
    95     }
    91 
    96 
    92     Item {
    97     Item {
    93         id: stack
    98         id: stack