C++ 入門指南 4.01
練習 29.3 參考程式 - 練習 QML 的 Button
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
Button {
width: 50
height: 50
text: qsTr("按鈕一")
onClicked: root.color = "yellow"
}
}
Row {
width: 200
height: 50
Rectangle {
id: rect2
width: 50
height: 50
}
Button {
width: 50
height: 50
text: qsTr("按鈕二")
onClicked: rect2.color = "blue"
}
}
Row {
width: 200
height: 50
Rectangle {
id: rect3
width: 100
height: 50
}
Button {
width: 50
height: 50
text: qsTr("按鈕三")
onClicked: rect3.color = "green"
}
}
Row {
width: 200
height: 50
Rectangle {
id: rect4
width: 150
height: 50
}
Button {
width: 50
height: 50
text: qsTr("按鈕四")
onClicked: rect4.color = "red"
}
}
}
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:main.qml
功能:示範設定視窗元件的顏色
作者:張凱慶 */
回到練習題目