1. 程式人生 > >QML實現多選按鈕

QML實現多選按鈕

import istview lsi text tex eight mouse delegate parent

這裏使用了條件表達式


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: "lightblue"
            Text {
                anchors.centerIn: parent
                text: index
                font.pixelSize: 30
            }
            border.color: "black"

            MouseArea {
                anchors.fill: parent
                onClicked:  {
                    console.log(delegateItem.color)
                  delegateItem.color = (delegateItem.color == "#add8e6")?"lightyellow":"#add8e6"
                }
            }
        }
    }


}

QML實現多選按鈕