파일 선택기 사용 Qt Quick Controls
File selectors 파일 변형을 편리하게 선택할 수 있는 방법을 제공합니다. Qt는 플랫폼 이름과 로케일을 내장 선택기로 제공합니다. ` Qt Quick Controls `는 애플리케이션이 실행 중인 스타일의 이름(대문자 표기)을 사용하여 내장 선택기를 확장합니다.
파일 선택기를 사용하면 스타일에 대한 엄격한 종속성을 생성하지 않고도 스타일별 조정을 적용할 수 있습니다. 사용 가능한 파일 변형 중 선택된 QML 파일만 QML 엔진에 의해 로드됩니다. 각 파일 변형은 컨텍스트, 즉 특정 스타일을 가질 수 있습니다. 이는 일반적으로 코드 중복을 초래하지만, 반면에 앞서 언급한 스타일과의 강고한 의존성을 제거하여 더 간단하고 효율적인 QML 코드를 만들어 줍니다.
다음 예제는 Material 스타일에서는 스타일화된 그림자가 적용되고, 다른 스타일에서는 플랫하게 보이는 사용자 정의 둥근 버튼을 보여줍니다. 파일은 CustomButton.qml 의 Material 버전이 +Material 하위 디렉터리에 배치되도록 구성되었습니다.
:/main.qml
:/CustomButton.qml
:/+Material/CustomButton.qml기본적으로 main.qml 는 CustomButton 유형에 대해 CustomButton.qml 를 사용합니다. 하지만 애플리케이션이 Material 스타일로 실행될 경우, Material 선택기가 존재하게 되며 대신 +Material/CustomButton.qml 버전이 사용됩니다.
// main.qml
import QtQuick
import QtQuick.Controls
ApplicationWindow {
id: window
visible: true
CustomButton {
text: "Button"
anchors.centerIn: parent
}
}사용자 정의 버튼의 기본 구현은 단순한 둥근 평면 버튼입니다.
// CustomButton.qml
import QtQuick
import QtQuick.Controls
Button {
id: control
background: Rectangle {
radius: width / 2
implicitWidth: 36
implicitHeight: 36
color: control.pressed ? "#ccc" : "#eee"
}
}Material 스타일의 사용자 정의 버튼 구현은 Material 스타일을 가져오고, 밝은 색상의 텍스트를 얻기 위해 다크 테마를 요청하며, 배경에 드롭 섀도우를 생성합니다.
// +Material/CustomButton.qml
import QtQuick
import QtQuick.Effects
import QtQuick.Controls
import QtQuick.Controls.Material
Button {
id: control
Material.theme: Material.Dark
background: Rectangle {
implicitWidth: 48
implicitHeight: 48
color: Material.accentColor
radius: width / 2
layer.enabled: control.enabled
layer.effect: MultiEffect {
shadowEnabled: true
shadowHorizontalOffset: 3
shadowVerticalOffset: 3
shadowColor: Material.dropShadowColor
shadowBlur: control.pressed ? 0.8 : 0.4
}
}
}참고: 내부적으로 ` QQmlFileSelector ` 인스턴스를 생성하는 ` QQmlApplicationEngine`을 사용하는것이 좋습니다. 이것이 QML 파일 선택자를 사용하기 위해 필요한 전부입니다.
관련 정보
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.