[QT QML]ApplicationWindow and Window

๐Ÿ‘‰๐Ÿป QT QML์—์„œ ์œˆ๋„์šฐ ๊ตฌํ˜„์‹œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์œˆ๋„์šฐ ํƒ€์ž…๊ณผ ์œˆ๋„์šฐ ํƒ€์ž…์— ๋Œ€ํ•œ ์„ค๋ช…์ž…๋‹ˆ๋‹ค.
This is a description of application window types and window types when implementing windows in QT QML.

๐Ÿ‘‰๐Ÿป Window :

โœ”๏ธ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ์œˆ๋„์šฐ ์ปจํ…Œ์ด๋„ˆ. ๋‹จ์ˆœ ์ฐฝ์œผ๋กœ, ๋ฉ”๋‰ด, ํˆด๋ฐ”, ์ƒํƒœ๋ฐ” ๋“ฑ ๊ณ ๊ธ‰ UI ๊ตฌ์„ฑ ์š”์†Œ๋Š” ์—†์Šต๋‹ˆ๋‹ค.
The most basic window container. It’s a simple window, lacking advanced UI elements like menus, toolbars, or status bars.

โœ”๏ธ ์œˆ๋„์šฐ๋Š” ๊ฒŒ์ž„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜, ๋‹จ์ˆœ ๋„๊ตฌ UI, ํŒ์—…์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
Windows is used for implementing games, simulations, simple tool UIs, and pop-ups.

๐Ÿ‘‰๐Ÿป ApplicationWindow :

โœ”๏ธ Window๋ฅผ ์ƒ์†๋ฐ›์•„ Qt Quick Controls 2์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ฉ”๋‰ด๋ฐ”, ํˆด๋ฐ”, ์ƒํƒœ๋ฐ” ๋“ฑ์„ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ™•์žฅ๋œ ์œˆ๋„์šฐ ํƒ€์ž…์ž…๋‹ˆ๋‹ค.
This is an extended window type that inherits from Window and allows easy use of menu bars, toolbars, status bars, etc. provided by Qt Quick Controls 2.

โœ”๏ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์œˆ๋„์šฐ๋Š” ์ผ๋ฐ˜ ๋ฐ์Šคํฌํƒ‘ ์•ฑ, ๋ฉ”๋‰ด/ํˆด๋ฐ”/์ƒํƒœ๋ฐ” ํ•„์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋‚˜ macOS ์‹œ์Šคํ…œ ๋ฉ”๋‰ด ์—ฐ๋™ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
Application windows are used when general desktop apps require menus/toolbars/status bars, or when macOS system menu integration is required.

๐Ÿ‘‰๐Ÿป MacOS ๋ฉ”๋‰ด ํŠน์ง• / MacOS Menu Features

โœ”๏ธMacOS์—์„œ๋Š” ์•„๋ž˜์˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ํ”„๋กœ๊ทธ๋žจ์˜ ๋ฉ”๋‰ด๋Š” ์œˆ๋„์šฐ์— ๋ถ™์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
On MacOS, the program’s menu is attached to the window, as shown in the picture below.

โœ”๏ธ MacOS์˜ ์‹œ์Šคํ…œ๋ฉ”๋‰ด์™€ ์ถฉ๋Œํ•˜๋Š” ๊ฒฝ์šฐ ๋ฉ”๋‰ด๊ฐ€ ๋‚˜ํƒ€๋‚˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
If there is a conflict with the system menu of macOS, the menu may not appear.

๐Ÿ‘‰๐Ÿป ์œˆ๋„์šฐ ํƒ€์ž…๊ณผ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ฐจ์ด์ 
Differences between Windows types and applications

ํ•ญ๋ชฉ / ItemWindowApplicationWindow
menuBar ์ง€์›
menuBar support
์—†์Œ / No์žˆ์Œ (menuBar ์†์„ฑ)
Yes (menuBar property)
toolBar ์ง€์›
toolBar support
์—†์Œ / No์žˆ์Œ (toolBar ์†์„ฑ)
Yes (toolBar property)
statusBar ์ง€์›
statusBar support
์—†์Œ / No์žˆ์Œ (statusBar ์†์„ฑ)
Yes (statusBar property)
๋ ˆ์ด์•„์›ƒ
Layout
๋‹จ์ˆœ / Simple๋ฉ”๋‰ด/ํˆด๋ฐ”/์ƒํƒœ๋ฐ”๊ฐ€ ๋ ˆ์ด์•„์›ƒ์— ์ž๋™ ๋ฐฐ์น˜๋จ
Menu/ToolBar/StatusBar automatically managed
๊ธฐ๋ณธ ์ปจํŠธ๋กค
Built-in controls
์—†์Œ / NoQt Quick Controls 2 ์ปดํฌ๋„ŒํŠธ์™€ ํ˜ธํ™˜ ์ตœ์ ํ™”
Optimized for Qt Quick Controls 2 components
macOS ๋ฉ”๋‰ด๋ฐ”
macOS system menu
์‹œ์Šคํ…œ ๋ฉ”๋‰ด๋ฐ”์™€ ์—ฐ๋™ ๋ถˆ๊ฐ€๋Šฅํ•จ
Not supported
macOS ์‹œ์Šคํ…œ ๋ฉ”๋‰ด๋ฐ”์™€ ์ž๋™ ์—ฐ๋™
Automatically integrated with macOS system menu bar
์œˆ๋„์šฐ ๋‚ด๋ถ€ ๋ฉ”๋‰ด
Internal window menu
๊ตฌํ˜„ ํ•„์š”
Must be implemented manually
menuBar ์†์„ฑ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
Available via menuBar property

๐Ÿ‘‰๐Ÿป ์ฝ”๋“œ / Code

โœ”๏ธ ์•„๋ž˜๋Š” ์œˆ๋„์šฐ ํƒ€์ž…๊ณผ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์œˆ๋„์šฐ ํƒ€์ž…์—์„œ ๋ฉ”๋‰ด๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.
Below is the code that implements the menu in the window type and application window type.

โœ”๏ธ์œˆ๋„์šฐ ํƒ€์ž…์—์„œ๋Š” ๋ฉ”๋‰ด๋ฅผ ๊ตฌํ˜„ํ•ด์•ผํ•˜๋ฉฐ MacOS์™€ ํ˜ธํ™˜๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
The Windows type requires the implementation of a menu and is not compatible with MacOS.

โœ”๏ธMain.qml

import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Window")


    Column {
        anchors.fill: parent

        Rectangle {
            color:"lightblue"
            width:parent.width
            height:30 // ๋†’์ด ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด Recangle์ด ์•ˆ๋ณด์ž„ / Recangle is not visible if height is not specified

            Row{
                anchors.left: parent.left // Row์˜ ์™ผ์ชฝ์„ column์˜ ์™ผ์ชฝ์— ๋งž์ถ”๊ธฐ / Align the left side of the row to the left side of the column
                anchors.leftMargin: 10 // ์ขŒ์ธก ๊ฐ„๊ฒฉ
                anchors.verticalCenter: parent.verticalCenter // ์ˆ˜์ง ์ค‘์•™ ์ •๋ ฌ / vertical center alignment

                spacing : 20 // Row์•ˆ์— ์žˆ๋Š” ์•„์ดํ…œ๋“ค์˜ ๊ฐ„๊ฒฉ / Spacing between items in a row

                Text {
                    id:fileText
                    text: "File"
                    color: "#333"
                    MouseArea {
                        
                        // ๋งˆ์šฐ์Šค ํด๋ฆญ ์˜์—ญ์„ Text์ „์ฒด๋กœ ์„ค์ •
                        // Set the mouse click area to the entire text
                        
                        anchors.fill: parent
                        onClicked: fileMenu.open(fileText)
                    }
                }
                Text {
                    id:editText
                    text: "Edit";
                    color: "#333"

                    MouseArea {
                        anchors.fill : parent
                        onClicked: editMenu.open(editText)
                    }
                }
            }

        }
        Text{
            text : "Window"
            font.pixelSize: 25
            anchors.centerIn: parent

        }

        // File ๋ฉ”๋‰ด / File Menu
        Menu {
            id: fileMenu
            title: "File"
            MenuItem { text: "New" }
            MenuItem { text: "Open..." }
            MenuItem { text: "Save" }
            MenuItem {
                text: "Open ApplicatioonWindow"
                onTriggered: {

                    // ์ƒˆ์ฐฝ ๋„์šฐ๊ธฐ,ApplicationWindow.qml ๋ถˆ๋Ÿฌ์˜ค๊ธฐ 
                    // Open a new window, load ApplicationWindow.qml
                    
                    var component = Qt.createComponent("ApplicationWindow.qml")
                    if (component.status === Component.Ready) {
                        var newWin = component.createObject(null)  // parent ์—†์ด ์ƒˆ ์ฐฝ / New window without parent
                        if (newWin) newWin.visible = true
                    } else {
                        console.log("Error loading component:", component.errorString())
                    }
                }
            }
            MenuItem { text: "Exit" }
        }

        // Edit ๋ฉ”๋‰ด / Edit Menu
        Menu {
            id: editMenu
            title: "Edit"
            MenuItem { text: "Copy" }
            MenuItem { text: "Paste" }
            MenuItem { text: "Cut" }
        }
    }
}

๐Ÿ‘‰๐Ÿป ApplicationWindow.qml

โœ”๏ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์œˆ๋„์šฐ ํƒ€์ž…์—์„œ๋Š” ๋ฉ”๋‰ด๋“ฑ์„ ๊ตฌํ˜„ํ•˜๊ธฐ๊ฐ€ ์‰ฝ๊ณ  MacOS์™€ ๋ฉ”๋‰ดํ˜ธํ™˜์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
In the application window type, it is easy to implement menus, etc., and menu compatibility with MacOS is possible.

import QtQuick
import QtQuick.Controls

ApplicationWindow {
    width: 400
    height: 300
    visible: true

    menuBar: MenuBar {
        Menu {
            title: "File"
            MenuItem { text: "Open" }
            MenuItem { text: "Close window"; onTriggered: Qt.quit() } //real exit
            MenuItem { text: "Exit" } // macOS์—์„œ๋Š” ์•ˆ๋‚˜ํƒ€๋‚จ / It doesn't appear on macOS
        }
    }

    Column{
        anchors.fill: parent

        Text{
            text: "Application Window"
            font.pixelSize: 25
            anchors.centerIn: parent
        }

    }
}

๐Ÿ‘‰๐Ÿป ์Šคํฌ๋ฆฐ ์ƒท / ScreenShot

https://youtu.be/oL-HIUkQLIo

Leave a Reply