Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicktoolbar.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
8
10
11/*!
12 \qmltype ToolBar
13 \inherits Pane
14//! \nativetype QQuickToolBar
15 \inqmlmodule QtQuick.Controls
16 \since 5.7
17 \ingroup qtquickcontrols-containers
18 \brief Container for context-sensitive controls.
19
20 ToolBar is a container of application-wide and context sensitive
21 actions and controls, such as navigation buttons and search fields.
22 ToolBar is commonly used as a \l {ApplicationWindow::header}{header}
23 or a \l {ApplicationWindow::footer}{footer} of an \l ApplicationWindow.
24
25 ToolBar does not provide a layout of its own, but requires you to
26 position its contents, for instance by creating a \l RowLayout. If only
27 a single item is used within the ToolBar, it will resize to fit the
28 implicit size of its contained item. This makes it particularly suitable
29 for use together with layouts.
30
31 \image qtquickcontrols-toolbar.png
32 {Toolbar containing buttons and other controls}
33
34 \code
35 ApplicationWindow {
36 visible:true
37
38 header: ToolBar {
39 RowLayout {
40 anchors.fill: parent
41 ToolButton {
42 text: qsTr("‹")
43 onClicked: stack.pop()
44 }
45 Label {
46 text: "Title"
47 elide: Label.ElideRight
48 horizontalAlignment: Qt.AlignHCenter
49 verticalAlignment: Qt.AlignVCenter
50 Layout.fillWidth: true
51 }
52 ToolButton {
53 text: qsTr("⋮")
54 onClicked: menu.open()
55 }
56 }
57 }
58
59 StackView {
60 id: stack
61 anchors.fill: parent
62 }
63 }
64 \endcode
65
66 \sa ApplicationWindow, ToolButton, {Customizing ToolBar}, {Container Controls}
67*/
68
70{
71public:
72 QPalette defaultPalette() const override { return QQuickTheme::palette(QQuickTheme::ToolBar); }
73
74 bool handlePress(const QPointF &point, ulong timestamp) override;
75
77};
78
79QQuickToolBar::QQuickToolBar(QQuickItem *parent)
80 : QQuickPane(*(new QQuickToolBarPrivate), parent)
81{
82}
83
84/*!
85 \qmlproperty enumeration QtQuick.Controls::ToolBar::position
86
87 This property holds the position of the toolbar.
88
89 \note If the toolbar is assigned as a header or footer of \l ApplicationWindow
90 or \l Page, the appropriate position is set automatically.
91
92 Possible values:
93 \value ToolBar.Header The toolbar is at the top, as a window or page header.
94 \value ToolBar.Footer The toolbar is at the bottom, as a window or page footer.
95
96 The default value is style-specific.
97
98 \sa ApplicationWindow::header, ApplicationWindow::footer, Page::header, Page::footer
99*/
100QQuickToolBar::Position QQuickToolBar::position() const
101{
102 Q_D(const QQuickToolBar);
103 return d->position;
104}
105
106void QQuickToolBar::setPosition(Position position)
107{
108 Q_D(QQuickToolBar);
109 if (d->position == position)
110 return;
111
112 d->position = position;
113 emit positionChanged();
114}
115
116QFont QQuickToolBar::defaultFont() const
117{
118 return QQuickTheme::font(QQuickTheme::ToolBar);
119}
120
121#if QT_CONFIG(accessibility)
122QAccessible::Role QQuickToolBar::accessibleRole() const
123{
124 return QAccessible::ToolBar;
125}
126#endif
127
128bool QQuickToolBarPrivate::handlePress(const QPointF &point, ulong timestamp)
129{
130 if (position == QQuickToolBar::Header && window && parent == window
131 && window->flags() & (Qt::ExpandedClientAreaHint | Qt::NoTitleBarBackgroundHint)
132 && qobject_cast<QQuickApplicationWindow*>(window)) {
133 if (window->startSystemMove())
134 return true;
135 }
136
137 return QQuickPanePrivate::handlePress(point, timestamp);
138}
139
140QT_END_NAMESPACE
141
142#include "moc_qquicktoolbar_p.cpp"
Container for context-sensitive controls.
QPalette defaultPalette() const override
bool handlePress(const QPointF &point, ulong timestamp) override
Combined button and popup list for selecting options.