QML and Qt Quick
2020.01.04 17:35

ApplicationWindow 와 메뉴바(MenuBar)구성

조회 수 3576 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

이 글은 QtQuick기반 응용프로그램 개발 시 Window 에 메뉴바(MenuBar)와 메뉴 아이템을 추가하는 방법을 설명한다.

 

ApplicationWindow.png

 

응용프로그램에 메뉴바를 구성하려면 ApplicationWindow 를 루트 아이템으로 생성해야한다. 다음의 간단한 예제를 보자.

 

main.qml

import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.2

ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MyMenuBar{
        id: menubar
        fileDialog: browse
    }

    FileDialog{
        id: browse
        nameFilters: [ "Image files (*.jpg *.png)", "All files (*)" ]
    }
}

 

main.qml에서 ApplicationWindow 는 Window 에서 파생된 형태의 아이템이다. Window에 추가적으로 다음과 같은 프로퍼티들이 추가된다.

contentItem : Item
footer : Item
header : Item
menuBar : Item

 

QML에서 창의 속성, 모양 및 레이아웃을 제어 할 수 있으며 menuBar프로퍼티에 MenuBar 유형의 아이템을 추가할 수 있다.

qtquickcontrols2-applicationwindow-wireframe.png

▲ApplicationWindow 레이아웃

 

MyMenuBar.qml

import QtQuick 2.0
import QtQuick.Controls 2.12

MenuBar{
    property var fileDialog: null
    Menu{
        id: file
        title: qsTr("File")
        
        Action {
            text: qsTr("&New...")
        }
        Action {
            text: qsTr("&Open...")
            shortcut: "Ctrl+N"
            onTriggered: { fileDialog.open() }
        }
        Action {
            text: qsTr("&Save")
        }
        Action {
            text: qsTr("Save &As...")
        }
        MenuSeparator { }
        Action {
            text: qsTr("E&xit...")
            onTriggered: Qt.quit()
        }
    }
    
    Menu{
        id: edit
        title: qsTr("Edit")
        Action {
            text: qsTr("&Copy...")
        }
        Action {
            text: qsTr("&Paste...")
        }
        Action {
            text: qsTr("&Delete...")
        }
    }
    
    Menu{
        id: help
        title: qsTr("Help")
        Action {
            text: qsTr("&About...")
        }
    }
}

 

MenuBar에는 Menu 아이템을 포함하고 있으며 Menu에는 세부 액션(Action)들을 추가할 수 있다. Action은 행동을 정의하는 것으로 사용자의 요청을 응용프로그램이 처리할 수 있도록 triggered 시그널을 제공한다. (GoF의 디자인 패턴중 Command 패턴과 같다.)

 

위의 예제에서 사용자가 "Open"을 요청하면 파일다이얼로그(FileDialog)을 열도록 되어있음을 알 수 있다.


  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views110094
    read more
  2. UI 폼(Form)작성 시 탭 순서(Tab Order) 설정

    Date2020.08.24 CategoryGeneral and Desktop Bymakersweb Views7196
    Read More
  3. No Image

    Qt로 데이터를 직렬화(serialization)하는 방법

    Date2020.08.04 CategoryC++ Class Bymakersweb Views5187
    Read More
  4. 최초의 Qt 6.0 스냅샷 제공 (First Qt 6.0 Snapshot Available)

    Date2020.06.21 CategoryQt 6 Byj2doll Views3409
    Read More
  5. Qt MQTT 에 대해서

    Date2020.06.02 CategoryMobile and Embedded Bymakersweb Views3086
    Read More
  6. Embedded Linux 에서 Qt 및 Graphics Stack

    Date2020.05.27 By운영자 Views2883
    Read More
  7. ShaderEffect QML Type을 이용한 버튼 클릭 효과

    Date2020.05.22 CategoryQML and Qt Quick Bymakersweb Views3568
    Read More
  8. Qt기반의 서버와 클라이언트간 SOAP(Simple Object Access Protocol)

    Date2020.05.11 CategoryGeneral and Desktop Bymakersweb Views3193
    Read More
  9. No Image

    재진입(Reentrancy) 및 스레드 안전성(Thread-Safety)

    Date2020.04.19 CategoryC++ Class Bymakersweb Views4294
    Read More
  10. No Image

    Qt 5.15 및 Qt 6의 출시 일정

    Date2020.04.09 CategoryQt 6 Bymakersweb Views3186
    Read More
  11. 콘솔에서 사용자 입력받기

    Date2020.03.22 CategoryGeneral and Desktop Bymakersweb Views55263
    Read More
  12. No Image

    컨테이너 클래스 - QVector

    Date2020.03.17 CategoryC++ Class Bymakersweb Views5516
    Read More
  13. Qt로 작성된 안드로이드 APP에 Splash Screen을 추가

    Date2020.03.10 CategoryMobile and Embedded Bymakersweb Views3188
    Read More
  14. No Image

    QLabel의 텍스트 색과 배경색을 변경

    Date2020.02.25 CategoryC++ Class Bymakersweb Views10103
    Read More
  15. 라즈베리파이4에 대한 Qt 5.14.1 크로스컴파일

    Date2020.02.12 CategoryMobile and Embedded Bymakersweb Views7025
    Read More
  16. QOpenGLWidget 을 투명하게 적용

    Date2020.02.05 CategoryGeneral and Desktop Bymakersweb Views3774
    Read More
  17. No Image

    2020년에 변경되는 Qt 오퍼 (Qt offering changes 2020)

    Date2020.01.31 CategoryGeneral and Desktop Byj2doll Views3086
    Read More
  18. No Image

    Qt로 XML 파싱 : Qt 6에서 업데이트된 (Parsing XML with Qt: Updates for Qt 6)

    Date2020.01.16 CategoryQt 6 Byj2doll Views3590
    Read More
  19. No Image

    Qt 멀티 스레드 프로그래밍 시 유의해야 할 몇 가지

    Date2020.01.13 CategoryGeneral and Desktop Bymakersweb Views7917
    Read More
  20. ApplicationWindow 와 메뉴바(MenuBar)구성

    Date2020.01.04 CategoryQML and Qt Quick Bymakersweb Views3576
    Read More
  21. No Image

    QThread 소개 및 예제

    Date2019.12.25 CategoryC++ Class Bymakersweb Views24540
    Read More
Board Pagination Prev 1 2 3 4 5 6 9 Next
/ 9