1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \page qtquickcontrols-fileselectors.html
6 \title Using File Selectors with Qt Quick Controls
8 \l {QFileSelector}{File selectors} provide a convenient way of selecting
9 file variants. Qt offers the platform name and the locale as built-in
10 selectors. Qt Quick Controls extends the built-in selectors with the name
11 (lowercase) of the style that an application is running with.
13 By using file selectors, style-specific tweaks can be applied without
14 creating a hard dependency to a style. From the available file variants,
15 only the selected QML file is loaded by the QML engine. Each file variant
16 can assume the context, that is, a specific style. This typically leads
17 to some code duplication, but on the other hand, cuts the aforementioned
18 hard dependency to the style, and leads to simpler and more efficient
21 The following example demonstrates a custom rounded button that has a
22 styled drop shadow in the \l {Material Style}{Material style}, and looks
23 flat in other styles. The files are organized so that the Material version
24 of \c CustomButton.qml is placed into a \c +Material sub-directory.
29 :/+Material/CustomButton.qml
32 By default, \c main.qml will use \c CustomButton.qml for the \c CustomButton
33 type. However, when the application is run with the Material style, the
34 \c Material selector will be present and the \c +Material/CustomButton.qml
35 version will be used instead.
40 import QtQuick.Controls
48 anchors.centerIn: parent
53 The base implementation of the custom button is a simple rounded
59 import QtQuick.Controls
64 background: Rectangle {
68 color: control.pressed ? "#ccc" : "#eee"
73 The Material style's implementation of the custom button imports the
74 Material style, requests a dark theme to get light text, and creates
75 a drop shadow for the background.
78 // +Material/CustomButton.qml
80 import QtGraphicalEffects
81 import QtQuick.Controls
82 import QtQuick.Controls.Material
87 Material.theme: Material.Dark
89 background: Rectangle {
92 color: Material.accentColor
95 layer.enabled: control.enabled
96 layer.effect: DropShadow {
98 color: Material.dropShadowColor
99 samples: control.pressed ? 20 : 10
106 \note It is recommended to use \l QQmlApplicationEngine, which internally
107 creates a \l QQmlFileSelector instance. This is all that is needed to take
108 QML file selectors into use.
110 \section1 Related Information
112 \li \l {QFileSelector}
113 \li \l {QQmlFileSelector}
114 \li \l {Styling Qt Quick Controls}