Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtquickcontrols-fileselectors.qdoc
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qtquickcontrols-fileselectors.html
6 \title Using File Selectors with Qt Quick Controls
7
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 (Capitalized) of the style that an application is running with.
12
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
19 QML code.
20
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.
25
26 \code
27 :/main.qml
28 :/CustomButton.qml
29 :/+Material/CustomButton.qml
30 \endcode
31
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.
36
37 \code
38 // main.qml
39 import QtQuick
40 import QtQuick.Controls
41
42 ApplicationWindow {
43 id: window
44 visible: true
45
46 CustomButton {
47 text: "Button"
48 anchors.centerIn: parent
49 }
50 }
51 \endcode
52
53 The base implementation of the custom button is a simple rounded
54 flat button.
55
56 \code
57 // CustomButton.qml
58 import QtQuick
59 import QtQuick.Controls
60
61 Button {
62 id: control
63
64 background: Rectangle {
65 radius: width / 2
66 implicitWidth: 36
67 implicitHeight: 36
68 color: control.pressed ? "#ccc" : "#eee"
69 }
70 }
71 \endcode
72
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.
76
77 \code
78 // +Material/CustomButton.qml
79 import QtQuick
80 import QtQuick.Effects
81 import QtQuick.Controls
82 import QtQuick.Controls.Material
83
84 Button {
85 id: control
86
87 Material.theme: Material.Dark
88
89 background: Rectangle {
90 implicitWidth: 48
91 implicitHeight: 48
92 color: Material.accentColor
93 radius: width / 2
94
95 layer.enabled: control.enabled
96 layer.effect: MultiEffect {
97 shadowEnabled: true
98 shadowHorizontalOffset: 3
99 shadowVerticalOffset: 3
100 shadowColor: Material.dropShadowColor
101 shadowBlur: control.pressed ? 0.8 : 0.4
102 }
103 }
104 }
105 \endcode
106
107 \note It is recommended to use \l QQmlApplicationEngine, which internally
108 creates a \l QQmlFileSelector instance. This is all that is needed to take
109 QML file selectors into use.
110
111 \section1 Related Information
112 \list
113 \li \l {QFileSelector}
114 \li \l {QQmlFileSelector}
115 \li \l {Styling Qt Quick Controls}
116 \endlist
117*/