Provides a container for items on a ToolBar that automatically implements an appropriate layout for its children. More...
Inherits Item
For more information on how to use ToolBarLayout inside ToolBar, see the ToolBar documentation. It provides also various use cases, for example, attaching a ToolBarLayout to a Page.
The ToolBarLayout is meant for specifying the tools within a ToolBar. The ToolBarLayout is a container that calculates the child positions based on platform specific rules.
In this example, there is a simple ToolBarLayout that must be set to be the tools of a ToolBar (or Page) at some point. The screenshot below each code snippet shows the result of that code snippet.
ToolBarLayout { id: toolBarLayout1 ToolButton { iconSource: "toolbar-back" onClicked: Qt.quit() } ToolButton { iconSource: "toolbar-menu" onClicked: launchMenu() } }
In most cases, the layout should contain a back ToolButton and a menu ToolButton.

It is possible to add a number of ToolButton instances that contain icons.
ToolBarLayout { id: toolBarLayout3a ToolButton { visible: false } ToolButton { iconSource: "toolbar-mediacontrol-stop" } ToolButton { iconSource: "toolbar-mediacontrol-pause" } ToolButton { iconSource: "toolbar-mediacontrol-play" } ToolButton { visible: false } }
![]()
It is also possible to add a number of ToolButton instances that contain text.
ToolBarLayout { id: toolBarLayout2 ToolButton { iconSource: "toolbar-back" onClicked: pageStack.pop() } ToolButton { text: "One" } ToolButton { text: "Two" } ToolButton { iconSource: "toolbar-next" onClicked: pageStack.push(page3) } }

However, it is recommended that you use either text or icons for all the remaining ToolButton instances, and avoid mixing up the two types (not counting the back button and menu button which should always contain icons).
In most cases, it is recommended that the back button and the menu button are shown in the ToolBar. However, in some cases it may be desirable or necessary to hide them. By setting either or both of the buttons to be hidden, they reserve space in the layout.
ToolBarLayout { id: toolBarLayout2 ToolButton { visible: false } ToolButton { iconSource: "toolbar-mediacontrol-stop" } ToolButton { iconSource: "toolbar-mediacontrol-play" } ToolButton { visible: false } }
![]()
ToolBarLayout provides some special behavior when a ButtonRow is contained as a child item. The correct combination of child items can be used to achieve good quality layouts that still take advantage of the available screen real estate.
Consider the following example of a media player application. The media transport controls can be placed inside the ToolBar, but if they are first contained by a ButtonRow, then the behavior provides the appearance of a traditional "Cassette Recorder" controls. Here, the buttons are designed to mechanically move into the pressed state in order to illustrate the current playback state in a tactile way, whilst the segmented appearance is reminiscent of classic hardware design for the keypad arrangement.
ToolBarLayout { id: toolBarLayout3b ToolButton { iconSource: "toolbar-back" } ButtonRow { checkedButton: stop3b ToolButton { id: stop3b; iconSource: "toolbar-mediacontrol-stop" } ToolButton { iconSource: "toolbar-mediacontrol-pause" } ToolButton { iconSource: "toolbar-mediacontrol-play" } } ToolButton { iconSource: "toolbar-menu" } }
![]()
Note that in this case the back and menu buttons are present, so that the ButtonRow occupies only the central area.
However, if either of the first or last icon ToolButton instances are missing, and if the ButtonRow contains a sufficient number of ToolButtons, then the layout will automatically adjust to utilize the optimum amount of screen space.
ToolBarLayout { id: toolBarLayout4a ToolButton { iconSource: "toolbar-back" } ButtonRow { checkedButton: stop4a ToolButton { iconSource: "toolbar-mediacontrol-backwards" } ToolButton { id: stop4a iconSource: "toolbar-mediacontrol-stop" } ToolButton { iconSource: "toolbar-mediacontrol-play" } ToolButton { iconSource: "toolbar-mediacontrol-forward" } } }
![]()
Note also that in this case, the checkedButton belonging to the ButtonRow has been set to the item that should be checked by default. In the case of a media transport, the initial state is "stop" in this implementation.
In the case of a Symbian toolbar, the layout rules are as follows:
Child items that are not ButtonRow or ToolButton are not guaranteed to fit. However, if a component happens to fit into the vertical space of the ToolBar (which may be different in landscape orientation), then it is possible to place other components inside the ToolBarLayout. In this case, the implicit size or size of the item will be used to space out the items evenly, but behaviour is not guaranteed.
Avoid placing too many items in the ToolBar as they may not fit within the portrait screen width. In the case of ToolButtons, the following combinations are supported (although additional items may fit at a particular screen size):
| Configuration | ||||
|---|---|---|---|---|
| Back item present? | 0 | 0 | 1 | 1 |
| Menu item present? | 0 | 1 | 0 | 1 |
| Number of items supported | ||||
| ToolButton > Icon | 3 | 3 | 3 | 3 |
| ToolButton > Text | 2 | 2 | 2 | 2 |
| ButtonRow > ToolButton > Icon | 5 | 4 | 4 | 3 |
| ButtonRow > ToolButton > Text | 3 | 3 | 3 | 2 |
So, for example, in the case of a back button plus a menu button, it is possible to fit 3 ToolButtons containing icons in the remaining space. So the rules are:
In practice, for a given Screen Device Profile, you may be able to fit additional children. However, it is not guaranteed that they will fit in all supported Screen Device Profiles. It is recommended that you stay within these limits in order to guarantee that the layout will always look correct.
See also ToolBar, ButtonRow, ToolButton, TabButton, and Page.
read-onlybackButton : bool |
Deprecated.
Do not use this property. If you need to create a ToolBarLayout that does not have a back button at the left hand position, but the first child is also a ToolButton that contains an icon and no text, then the following approach should be used:
ToolBarLayout { id: toolBarLayout1 ToolButton { visible: false } ToolButton { iconSource: "toolbar-mediacontrol-play" } ToolButton { visible: false } }
In this example, the ToolButton in the first and last positions are set to be not visible. However, the ToolBarLayout still reserves space for them in the layout.