The Qt Quick Controls were originally developed to support desktop platforms, and later joined the support of mobile platforms and embedded platforms. They are widely used because they provide a flexible style system that allows for the development of applications with platform-related or unrelated styles.
In embedded systems, hardware resources are limited, the system may be relatively inefficient. The QT Quick Controls 2 is designed to solve this problem and can be used to guide development using benchmarks. C + + and QML
In many cases, the handling of internal states by C + + is more efficient. For example, in contrast to the process of handling events in C + +, the controls need to create internal mouseareas and bind the Keys object. style
Not only does handling events and logic in C + + improve performance, it also allows the QML layer of visualization to become a simpler declarative layer. This is reflected in the structure of the controls project: All visual implementations are in the Imports folder so that users who want to create their own full style can copy the folder and start adjusting. Look here to learn more about the implementation of the style plug-in.
In Qt Quick Controls 2, styles no longer provide components that are instantiated by controls, but controls contain item delegates that can be substituted. In fact, this means that delegates is a live instantiation of QT Quick item and as a property of control, and then simply associating control as a parent node. modularity and Simplification
In the case of complex controls, it is sometimes better to separate them into different blocks. For example, a complex ScrollView control:
ScrollView {
horizontalScrollBarPolicy:Qt.ScrollBarAlwaysOff
flickable {
//...
}
}
Instead, a simple scrollbar/scrollindicator control can be attached to any flickable:
flickable {
//...
ScrollBar.vertical:ScrollBar {}
}
The goal of the Qt Quick Controls 2 API is to become simpler and more straightforward. Regular operations are simple, and more complex operations can become document-type blocks of code that are copied into your code. Properties Comparison Table
~ |
Qt Quick Controls |
Qt Quick Controls 2 |
Styling the Delegates |
Yes |
Yes |
Built-in native styles |
Yes |
No |
Run-time Style/theme switch |
Yes1 |
Yes2 |
Available for desktop |
Yes |
Yes |
Available for Mobile |
Yes3 |
Yes |
Can be used for embedded |
Yes3 |
Yes |
Internal event handling |
QML |
C++ |
1. Unofficial support, but can be technically implemented via private API
2. Only theme can be toggled at run time, while style is fixed
3. Performance may not be the best migration of QT Quick controls code
The QT Quick CONTROLS2 API is very similar to QT quick controls, but it actually has some API changes to improve. The most changes are changes in style, and the delegate of all controls can be accessed through the control itself, rather than through detached style objects.
For example, to set the button's style in Qt Quick controls:
Button {
Style:buttonstyle {
Label:label {
//...
}
}}
In Qt Quick Controls2, it looks like this:
Button {
Contentitem:label {
//...
}
}
Prepare for Migration
A better way to migrate to Qt Quick controls 2 is to place each control with a custom style in a separate QML file. For example, the button on the QT Quick controls above can be moved to a file named Button.qml, then put the file in a folder called controls, and then proceed as follows:
Import "Controls" as controls
Controls.button {
...
}
This is done in both the old and new modules, and reduces the workload at the beginning of the migration. Type comparison Table
The first column lists all the available types in QT Quick Controls 1, QT Quick Dialogs, and QT quick extras, and the second column is the corresponding type in QT Quick Controls 2. If there is no direct workaround, the third column contains alternatives that provide the relevant functionality. The last column contains a description of the corresponding type differences within the two modules.
Qt Quick Controls 1 |
Qt Quick Controls 2 |
Alternative Scenarios |
Notes |
Action |
Action |
Shortcut (Qt Quick) |
|
Applicationwindow |
Applicationwindow |
|
|
Busyindicator |
Busyindicator |
|
|
Button |
Button |
|
|
Calendar |
– |
Monthgrid, Dayofweekrow, Weeknumbercolumn (Qt Labs Calendar) |
Qt Labs Calendar: Monthgrid, DayOfWeek, and Weeknumbercolumn belong to the non-stylized calendar view |
CheckBox |
CheckBox |
|
|
ComboBox |
ComboBox |
|
|
Exclusivegroup |
– |
Actiongroup, Buttongroup (Qt Quick Controls 2) |
Qt Quick Controls 2: Actiongroup and Buttongroup provide similar functionality |
GroupBox |
GroupBox |
|
|
Label |
Label |
|
|
Menu |
Menu |
Menu (Qt Labs Platform) |
Qt Quick Controls 1: menu is native to the platform on which the QT Platform Abstraction layer provides implementation. Other platforms use QML-based top-level menu pop-up windows. The menu supports traditional desktop-style cascading submenus, but does not work on embedded Linux because Eglfs does not support multiple top-level windows. Qt Quick Controls 2: menu is non-native, item-based, but a pop-up window stacked on top of the application's content. Therefore, the menu popup window is limited to the window boundaries. The menu is fully customizable by QML and QT Quick, and allows you to add any item. Traditional desktop features, such as cascading submenus and visual keyboard shortcuts, are not supported. Qt Labs Platform: menu is an experimental local menu that fallback to Qt Widgets on a platform that does not support the implementation of the QT platform Abstraction layer. |
MenuBar |
MenuBar |
MenuBar (Qt Labs Platform) |
Qt Quick Controls 1: MenuBar is native to the platform on which the QT Platform Abstraction layer provides implementation. Other platforms use the QML-based menu bar item stacked at the top of the window. Qt Quick Controls 2: MenuBar is a non-native menubar based on QML and can be customized using QML and QT quick. Qt Labs Platform: MenuBar is an experimental native menubar. It can only be used for platforms that support the native implementation of the QT platform Abstraction layer. |
MenuItem, Menuseparator |
MenuItem, Menuseparator |
MenuItem, Menuseparator (Qt Labs Platform) |
Qt Quick Controls 1: MenuItem and Menuseparator are native to platforms that support the implementation of the QT platform Abstraction layer. Other platforms use the QML-based menu item and separator. Qt Quick Controls 2: MenuItem and Menuseparator are non-native item based on QML and fully available QML and QT Quick custom styles. Qt Labs Platform: MenuItem and Menuseparator are experimental native menu item and separator |
ProgressBar |
ProgressBar |
|
|
RadioButton |
RadioButton |
|
|
ScrollView |
ScrollView |
|
|
Slider |
Slider |
|
|
Spinbox |
Spinbox |
|
|
SplitView |
– |
|
|
StackView, Stackviewdelegate, Stack |
StackView |
|
Qt Quick Controls 2: StackView provides customizable transformations and additional properties through a single stackview type. |
StatusBar |
– |
ToolBar (Qt Quick Controls 2) |
Qt Quick Controls 2: Applicationwindow allows you to assign any item or control such as toolbar as the header or footer. |
Switch |
Switch |
|
|
Tabview, Tab |
– |
TabBar, Tabbutton (Qt Quick Controls 2) |
Qt Quick Controls 2: TabBar and Tabbutton provide similar functions that can be used to construct tabbed views. |
TableView |
– |
|
|
TextArea |
TextArea |
|
Qt Quick Controls 1: TextArea inherits from ScrollView, so it is always a scrollable editor. Qt Quick Controls 2: TextArea is a simple multi-line editor that can optionally be attached to flickable to provide scrolling functionality. This allows the textarea to be used for scrollable pages without nested scrollable areas, which resolves usability issues. |
TextField |
TextField |
|
|
ToolBar |
ToolBar |
|
|
Toolbutton |
Toolbutton |
|
|
Treeview |
– |
|
|
Qt Quick Dialogs |
Qt Quick Controls 2 |
Alternative scenarios |
Note |
Dialog |
– |
Dialog |
Qt Quick Dialogs: Dialog can be a top-level window or an item-based popup, depending on whether the platform supports multiple top-level windows. Qt Quick Controls 2: Dialog is not a top-level window, but is an item-based pop-up content stacked on top of the program's content, so the dialog is limited to the window range. |
ColorDialog, FileDialog, FontDialog, Messagedialog |
– |
ColorDialog, FileDialog, Folderdialog, FontDialog, Messagedialog (Qt Labs Platform) |
Qt Quick Dialogs: dialog is native to platforms that support the implementation of the QT platform abstraction layer. Other platforms use QT widgets or QML based dialog, depending on whether the platform on which it resides supports multiple top-level windows. qt Labs Platform: Experimental Native dialog, fallback to QT Widgets on platforms that do not support the abstraction layer of the QT platform. |
Qt Quick Extras |
Qt Quick Controls 2 |
Alternative scenarios |
Note |
Circulargauge |
– |
|
|
Delaybutton |
Delaybutton |
|
|
Dial |
Dial |
|
|
Gauge |
– |
|
|
Picture |
– |
|
|
Piemenu |
– |
|
|
Statusindicator |
– |
|
|
ToggleButton |
– |
|
|
Tumbler, Tumblercolumn |
Tumbler |
|
Qt Quick Extras: Tumbler can contain multiple columns. Qt Quick Controls 2: The tumbler represents a separate scroll wheel. Multi-column can be composed of multiple tumbler arranged together. |
Not before. |
Qt Quick Controls 2 |
Alternative scenarios |
Note |
– |
AbstractButton |
|
|
– |
Actiongroup |
Exclusivegroup (Qt Quick Controls 1) |
Qt Quick Controls 1: Exclusivegroup provides similar functionality |
– |
Buttongroup |
Exclusivegroup (Qt Quick Controls 1) |
Qt Quick Controls 1: Exclusivegroup provides similar functionality |
– |
Checkdelegate |
|
|
– |
Container |
|
|
– |
Control |
|
|
– |
Drawer |
|
|
– |
Frame |
|
|
– |
Itemdelegate |
|
|
– |
Page |
|
|
– |
Pageindicator |
|
|
– |
Pane |
|
|
– |
Popup |
|
|
– |
Radiodelegate |
|
|
– |
Rangeslider |
|
|
– |
Roundbutton |
|
|
– |
ScrollBar, Scrollindicator |
ScrollView (Qt Quick Controls 1) |
Qt Quick Controls 1: The ScrollView provides similar functionality. It combines horizontal and vertical scrollbar and a background page that surrounds the scroll view. |
– |
– |
Standardpaths (Qt Labs Platform) |
Qt Quick Dialogs: FileDialog provides quick properties for easy reading of most standard paths. Qt Labs Platform: Standardpaths provides a separate type to provide a way to access the standard path. |
– |
Swipedelegate |
|
|
– |
Swipeview |
|
|
– |
Switchdelegate |
|
|
– |
– |
Systemtrayicon (Qt Labs Platform) |
Qt Labs Platform: Systemtrayicon is a native system tray icon for experimental systems. Qt WIdgets are fallback on platforms that do not support the QT Platform Abstraction layer implementation. |
– |
TabBar, Tabbutton |
Tabview (Qt Quick Controls 1) |
Qt Quick Controls 1: Tabview provides a similar approach. It consists of tab bar, background and tab-centered pages. |
– |
Toolseparator |
|
|
– |
ToolTip |
|
Qt Quick Controls 1: Button and action have built-in QT widgets-based tooltips. Qt Quick Controls 2: The tooltip can be attached to any item. |
Original link