aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc
blob: c80f8ccd4f8f98a3175839d8adda7f51b0ab98d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \page qtquickcontrols2-differences.html
    \title Differences between Qt Quick Controls

    Qt Quick Controls were originally developed to support desktop platforms,
    with mobile and embedded support coming shortly afterwards. They have a
    very broad scope, in that they provide a styling system flexible enough to
    allow the development of applications that have either a platform-dependent
    or platform-independent style.

    On embedded systems, where the hardware has limited resources, this approach
    can be inefficient. Qt Quick Controls 2 were designed to solve this problem,
    using
    \l {https://blog.qt.io/blog/2015/03/31/qt-quick-controls-for-embedded/}{benchmarks}
    to guide the development.

    \section2 C++ and QML

    In many cases, the internal state of a control can be more efficiently
    processed in C++. For example, handling input events in C++ makes a
    difference for controls that would otherwise need to create internal
    MouseAreas and attached Keys objects.

    \section2 Styles

    Not only does handling events and logic in C++ increase performance, but it
    allows the visual QML layer to be a simple, declarative layer on top. This
    is reflected in the structure of the controls project: all visual
    implementations sit in the \e imports folder, so that users who want to
    create their own complete style can copy the folder and start tweaking.
    Read more about implementing a style plugin
    \l {Creating a Custom Style}{here}.

    In Qt Quick Controls 2, styles no longer provide components that are
    dynamically instantiated by controls, but controls themselves consist of
    item delegates that can be replaced. In effect, this means that delegates
    are Qt Quick items that are instantiated on the spot, as properties of the
    control, and are simply parented to the control.

    \section2 Modularity and Simplicity

    When it comes to more complex controls, it is sometimes better to split
    them up into separate building blocks. As an example, the complex
    ScrollView control:

    \qml
    ScrollView {
        horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
        Flickable {
            // ...
        }
    }
    \endqml

    Is replaced with simple ScrollBar/ScrollIndicator controls that can be
    attached to any Flickable:

    \qml
    Flickable {
        // ...
        ScrollBar.vertical: ScrollBar { }
    }
    \endqml

    The API of Qt Quick Controls 2 aims to be clean and simple. Common
    operations are easy, and more advanced ones are liberally documented with
    snippets that can be copied into your code.

    \section2 Feature Comparison Table

    \table
    \header
        \li
        \li Qt Quick Controls
        \li Qt Quick Controls 2
    \row
        \li Stylable delegates
        \li Yes
        \li Yes
    \row
        \li Pre-built native styles
        \li Yes
        \li No
    \row
        \li Runtime style changes
        \li Yes
        \li Yes
    \row
        \li Can be used on Desktop
        \li Yes
        \li Yes \b *
    \row
        \li Can be used on Mobile
        \li Yes
        \li Yes
    \row
        \li Can be used on Embedded
        \li Yes
        \li Yes
    \row
        \li Internal event handling
        \li QML
        \li C++
    \endtable

    \b {* No hover support}

    \section2 Porting Qt Quick Controls Code

    The API of Qt Quick Controls 2 is very similar to Qt Quick Controls, but it
    does come with some changes necessary to facilitate the improvements. The
    majority of changes are to do with styling; all of a control's delegates
    are now accessible in the control itself, instead of in a separate style
    object.

    For example, to style a button in Qt Quick Controls:

    \badcode
    Button {
        style: ButtonStyle {
            label: Label {
                // ...
            }
        }
    }
    \endcode

    To style a button in Qt Quick Controls 2:

    \qml
    Button {
        contentItem: Label {
            // ...
        }
    }
    \endqml

    \section3 Preparing for Migration

    With this in mind, a good way to prepare for a migration to Qt Quick
    Controls 2 is to place each control that you have a custom style for in its
    own QML file. For example, the Qt Quick Controls button above could be moved to a
    file named Button.qml, and used in the following manner:

    \badcode
    import "controls" as Controls

    Controls.Button {
        ...
    }
    \endcode

    This works with both modules, and will reduce the amount of work needed
    when the migration begins.

    \section3 Type Changes

    \table
    \header
        \li Qt Quick Controls
        \li Qt Quick Controls 2
    \row
        \li \l [QML QtQuickControls] {Action}
        \li No equivalent; see \l [QML QtQuick] {Shortcut} instead.
    \row
        \li \l [QML QtQuickControls] {ApplicationWindow}
        \li \l [QML QtQuickControls2] {ApplicationWindow}
    \row
        \li \l [QML QtQuickControls] {BusyIndicator}
        \li \l [QML QtQuickControls2] {BusyIndicator}
    \row
        \li \l [QML QtQuickControls] {Button}
        \li \l [QML QtQuickControls2] {Button}
    \row
        \li \l [QML QtQuickControls] {Calendar}
        \li No equivalent; see \l [QML] {MonthGrid}, \l [QML] {DayOfWeekRow} and \l [QML] {WeekNumberColumn} instead.
    \row
        \li \l [QML QtQuickControls] {CheckBox}
        \li \l [QML QtQuickControls2] {CheckBox}
    \row
        \li \l [QML QtQuickControls] {ComboBox}
        \li \l [QML QtQuickControls2] {ComboBox}
    \row
        \li \l [QML QtQuickControls] {ExclusiveGroup}
        \li \l [QML QtQuickControls2] {ButtonGroup}
    \row
        \li \l [QML QtQuickControls] {GroupBox}

        \li \l [QtQuickControls2] {GroupBox}, or \l [QML QtQuickControls2] {Frame}
            if a title is not required.

    \row
        \li \l [QML QtQuickControls] {Label}
        \li \l [QML QtQuickControls2] {Label}
    \row
        \li \l [QML QtQuickControls] {Menu}
        \li \l [QML QtQuickControls2] {Menu}
    \row
        \li \l [QML QtQuickControls] {ProgressBar}
        \li \l [QML QtQuickControls2] {ProgressBar}
    \row
        \li \l [QML QtQuickControls] {RadioButton}
        \li \l [QML QtQuickControls2] {RadioButton}
    \row
        \li \l [QML QtQuickControls] {ScrollView}
        \li \l [QML QtQuickControls2] {ScrollBar},
            \l [QML QtQuickControls2] {ScrollIndicator}
    \row
        \li \l [QML QtQuickControls] {Slider}
        \li \l [QML QtQuickControls2] {Slider}
    \row
        \li \l [QML QtQuickControls] {SpinBox}
        \li \l [QML QtQuickControls2] {SpinBox}
    \row
        \li \l [QML QtQuickControls] {Stack},
            \l [QML QtQuickControls] {StackView},
            \l [QML QtQuickControls] {StackViewDelegate}
        \li \l [QML QtQuickControls2] {StackView}
    \row
        \li \l [QML QtQuickControls] {StatusBar}
        \li No equivalent
    \row
        \li \l [QML QtQuickControls] {Switch}
        \li \l [QML QtQuickControls2] {Switch}
    \row
        \li \l [QML QtQuickControls] {Tab},
            \l [QML QtQuickControls] {TabView}
        \li \l [QML QtQuickControls2] {TabBar} in combination with, for example,
            \l [QML QtQuickControls2] {SwipeView}.
    \row
        \li \l [QML QtQuickControls] {TableView}
        \li No equivalent
    \row
        \li \l [QML QtQuickControls] {TextArea}
        \li \l [QML QtQuickControls2] {TextArea}
    \row
        \li \l [QML QtQuickControls] {TextField}
        \li \l [QML QtQuickControls2] {TextField}
    \row
        \li \l [QML QtQuickControls] {ToolBar}
        \li \l [QML QtQuickControls2] {ToolBar}
    \row
        \li \l [QML QtQuickControls] {ToolButton}
        \li \l [QML QtQuickControls2] {ToolButton}
    \row
        \li \l [QML QtQuickControls] {TreeView}
        \li No equivalent
    \endtable

    \section1 Related Information

    \list
      \li \l{Qt Quick}
      \li \l{Qt Quick Controls}
      \li \l{Qt Quick Controls 2 QML Types}
    \endlist
*/