C++ 入門指南 4.01

練習 29.4 參考程式 - 練習 QML 的 MouseArea

import QtQuick
import QtQuick.Controls

ApplicationWindow {
    id: root
    width: 200
    height: 200
    visible: true
    title: qsTr("顏色滑鼠測試")

    Column {
        width: 200
        height: 200

        Row {
            width: 200
            height: 50

            MouseArea {
                anchors.fill: parent
                onClicked: root.color = "yellow"
            }
        }

        Row {
            width: 200
            height: 50

            Rectangle {
                id: rect2
                width: 50
                height: 50

                MouseArea {
                    anchors.fill: parent
                    onClicked: rect2.color = "blue"
                }
            }
        }

        Row {
            width: 200
            height: 50

            Rectangle {
                id: rect3
                width: 100
                height: 50

                MouseArea {
                    anchors.fill: parent
                    onClicked: rect3.color = "green"
                }
            }
        }

        Row {
            width: 200
            height: 50

            Rectangle {
                id: rect4
                width: 150
                height: 50

                MouseArea {
                    anchors.fill: parent
                    onClicked: rect4.color = "red"
                }
            }
        }
    }
}

/* 《程式語言教學誌》的範例程式
   http://kaiching.org/
   檔名:main.qml
   功能:示範 MouseArea 型態
   作者:張凱慶 */
回到練習題目

上一頁 練習 29.3 參考程式 - 練習 QML 的 Button
回 C++ 入門指南 4.01 目錄
下一頁 練習 29.5 參考程式 - 練習設計計算機外觀
回 C++ 教材
回程式語言教材首頁