C++ 入門指南 4.01

練習 29.5 參考程式 - 練習設計計算機外觀

import QtQuick
import QtQuick.Controls

ApplicationWindow {
    width: 320
    height: 480
    visible: true
    title: qsTr("計算機")

    Column {
        Row {
            width: 320
            height: 80

            Text {
                width: 320
                horizontalAlignment: Text.AlignRight
                text: "0"
                font {
                    pixelSize: 72
                }
            }
        }

        Row {
            width: 320
            height: 80

            Button {
                width: 80
                height: 80
                text: "C"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "±"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "%"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "÷"

                font {
                    pixelSize: 48
                }
            }
        }

        Row {
            width: 320
            height: 80

            Button {
                width: 80
                height: 80
                text: "7"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "8"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "9"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "×"

                font {
                    pixelSize: 48
                }
            }
        }

        Row {
            width: 320
            height: 80

            Button {
                width: 80
                height: 80
                text: "4"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "5"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "6"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "-"

                font {
                    pixelSize: 48
                }
            }
        }

        Row {
            width: 320
            height: 80

            Button {
                width: 80
                height: 80
                text: "1"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "2"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "3"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "+"

                font {
                    pixelSize: 48
                }
            }
        }

        Row {
            width: 320
            height: 80

            Button {
                width: 160
                height: 80
                text: "0"

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "."

                font {
                    pixelSize: 48
                }
            }

            Button {
                width: 80
                height: 80
                text: "="

                font {
                    pixelSize: 48
                }
            }
        }
    }
}

/* 《程式語言教學誌》的範例程式
   http://kaiching.org/
   檔名:main.qml
   功能:示範計算機的視窗外觀
   作者:張凱慶 */
回到練習題目

上一頁 練習 29.4 參考程式 - 練習 QML 的 MouseArea
回 C++ 入門指南 4.01 目錄
下一頁 練習 29.6 參考程式 - 練習設計小時鐘外觀
回 C++ 教材
回程式語言教材首頁