QML实现单选按钮(1)

这里用到了ListView.isCurrentItem判断是否是当前项目


import QtQuick 2.0

Item {

    id: root

    width: 1920

    height: 1080

    ListView {

        width: 600

        height: 800

        anchors.centerIn: parent

        model: 5

        delegate:

            Rectangle {

            id: delegateItem

            width: 100

            height: 50

            color: ListView.isCurrentItem? "pink":"lightblue"

            Text {

                anchors.centerIn: parent

                text: index

                font.pixelSize: 30

            }

            border.color: "black"

            MouseArea {

                anchors.fill: parent

                onClicked:  delegateItem.ListView.view.currentIndex = index

            }

        }

    }

}

posted @ 2018-09-29 09:49  学习写作  阅读(797)  评论(0编辑  收藏  举报