W3cubDocs

/Qt 5.11

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 benchmarks to guide the development.

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.

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 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 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.

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:

ScrollView {
    horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
    Flickable {
        // ...
    }
}

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

Flickable {
    // ...
    ScrollBar.vertical: ScrollBar { }
}

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.

Feature Comparison Table

Qt Quick Controls Qt Quick Controls 2
Stylable delegates Yes Yes
Pre-built native styles Yes No
Runtime style/theme changes Yes 1 Yes 2
Can be used on Desktop Yes Yes
Can be used on Mobile Yes 3 Yes
Can be used on Embedded Yes 3 Yes
Internal event handling QML C++
  1. Not officially supported, but technically possible via private APIs
  2. Only themes for specific styles can be changed at runtime, styles are fixed
  3. Performance may not be optimal

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:

Button {
    style: ButtonStyle {
        label: Label {
            // ...
        }
    }
}

To style a button in Qt Quick Controls 2:

Button {
    contentItem: Label {
        // ...
    }
}

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 in a directory named controls, and used in the following manner:

import "controls" as Controls

Controls.Button {
    ...
}

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

Type Comparison Table

The first column lists all types available in Qt Quick Controls 1, Qt Quick Dialogs, and Qt Quick Extras. The second column documents the respective type in Qt Quick Controls 2. When a direct alternative is not available, the third column contains an alternative that provides related functionality. The last column contains some remarks about the differences between the types in the different modules.

Qt Quick Controls 1 Qt Quick Controls 2 Alternatives Remarks
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 are experimental unstyled building blocks for calendar views.
CheckBox CheckBox
ComboBox ComboBox
ExclusiveGroup ActionGroup, ButtonGroup (Qt Quick Controls 2)
  • Qt Quick Controls 2: ActionGroup and ButtonGroup offer similar functionality.
GroupBox GroupBox
Label Label
Menu Menu Menu (Qt Labs Platform)
  • Qt Quick Controls 1: Menu is native on platforms where an implementation is available in the Qt Platform Abstraction Layer. Other platforms use a QML-based top-level menu popup window. 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 a non-native Item-based popup that is stacked above the application content. Due to this, menu popups are restricted within window boundaries. Menu is fully customizable using QML and Qt Quick, and allows adding any Items. Traditional desktop oriented features, such as cascading submenus and visualizing keyboard shortcuts are missing.
  • Qt Labs Platform: Menu is an experimental native menu that uses Qt Widgets as a fallback on platforms where a native implementation is not available in the Qt Platform Abstraction Layer.
MenuBar MenuBar MenuBar (Qt Labs Platform)
  • Qt Quick Controls 1: MenuBar is native on platforms where an implementation is available in the Qt Platform Abstraction Layer. Other platforms use a QML-based menubar item stacked at the top of the window.
  • Qt Quick Controls 2: MenuBar is a non-native QML-based menubar that can be fully customized using QML and Qt Quick.
  • Qt Labs Platform: MenuBar is an experimental native menubar. It is only available on platforms where a native implementation is available in the Qt Platform Abstraction Layer.
MenuItem, MenuSeparator MenuItem, MenuSeparator MenuItem, MenuSeparator (Qt Labs Platform)
  • Qt Quick Controls 1: MenuItem and MenuSeparator are native on platforms where an implementation is available in the Qt Platform Abstraction Layer. Other platforms use QML-based menu items and separators.
  • Qt Quick Controls 2: MenuItem and MenuSeparator are a non-native QML-based menu items and separators that can be fully customized using QML and Qt Quick.
  • Qt Labs Platform: MenuItem and MenuSeparator are experimental native menu items and separators.
ProgressBar ProgressBar
RadioButton RadioButton
ScrollView ScrollView
Slider Slider
SpinBox SpinBox
SplitView
StackView, StackViewDelegate, Stack StackView
  • Qt Quick Controls 2: StackView provides customizable transitions and attached properties via a single StackView type.
StatusBar ToolBar (Qt Quick Controls 2)
  • Qt Quick Controls 2: ApplicationWindow allows assigning any item or control, such as ToolBar, as a header or footer.
Switch Switch
TabView, Tab TabBar, TabButton (Qt Quick Controls 2)
  • Qt Quick Controls 2: TabBar and TabButton offer similar functionality, and can be used to build tabbed views.
TableView
TextArea TextArea
  • Qt Quick Controls 1: TextArea inherits ScrollView and is therefore always a scrollable editor.
  • Qt Quick Controls 2: TextArea is a simpler multi-line editor that can be optionally attached to a Flickable to provide scrolling functionality. This allows using TextArea in a scrollable page without having two nested scrollable areas, which can be problematic and cause usability issues.
TextField TextField
ToolBar ToolBar
ToolButton ToolButton
TreeView
Qt Quick Dialogs Qt Quick Controls 2 Alternatives Remarks
Dialog Dialog
  • Qt Quick Dialogs: Dialog is either a top-level window or an Item-based popup depending on whether the underlying platform supports multiple top-level windows.
  • Qt Quick Controls 2: Dialog is not a top-level window, but an Item-based popup that is stacked above the application content. Due to this, dialogs are restricted within window boundaries.
ColorDialog, FileDialog, FontDialog, MessageDialog ColorDialog, FileDialog, FolderDialog, FontDialog, MessageDialog (Qt Labs Platform)
  • Qt Quick Dialogs: Dialogs are native on platforms where an implementation is available in the Qt Platform Abstraction Layer. Other platforms use either Qt Widgets or QML-based dialogs depending on whether the underlying platform supports multiple top-level windows.
  • Qt Labs Platform: Experimental native dialogs that use Qt Widgets as a fallback on platforms where a native implementation is not available in the Qt Platform Abstraction Layer.
Qt Quick Extras Qt Quick Controls 2 Alternatives Remarks
CircularGauge
DelayButton DelayButton
Dial Dial
Gauge
Picture
PieMenu
StatusIndicator
ToggleButton
Tumbler, TumblerColumn Tumbler
  • Qt Quick Extras: Tumbler can consist of multiple columns.
  • Qt Quick Controls 2: Tumbler presents a single spinnable wheel. Multiple columns can be created by placing multiple Tumblers next to each other.
No Predecessor Qt Quick Controls 2 Alternatives Remarks
AbstractButton
ActionGroup ExclusiveGroup (Qt Quick Controls 1)
  • Qt Quick Controls 1: ExclusiveGroup offers similar functionality.
ButtonGroup ExclusiveGroup (Qt Quick Controls 1)
  • Qt Quick Controls 1: ExclusiveGroup offers 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: ScrollView offers similar functionality. It combines horizontal and vertical scrollbars, and the background and frame around the scrollable view.
StandardPaths (Qt Labs Platform)
  • Qt Quick Dialogs: FileDialog offers a shortcut property that can be used to access the most common standard paths.
  • Qt Labs Platform: StandardPaths offers a separate type to give full access to the standard paths.
SwipeDelegate
SwipeView
SwitchDelegate
SystemTrayIcon (Qt Labs Platform)
  • Qt Labs Platform: SystemTrayIcon is an experimental native system tray icon that uses Qt Widgets as a fallback on platforms where a native implementation is not available in the Qt Platform Abstraction Layer.
TabBar, TabButton TabView (Qt Quick Controls 1)
  • Qt Quick Controls 1: TabView offers similar functionality. It combines the tab bar, background and frame around the tabs.
ToolSeparator
ToolTip
  • Qt Quick Controls 1: Button and Action have built-in Qt Widgets-based tooltips.
  • Qt Quick Controls 2: ToolTip can be attached to any Item.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5/qtquickcontrols2-differences.html