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
33 \code
34 ApplicationWindow {
35 visible:true
36
37 header: ToolBar {
38 RowLayout {
39 anchors.fill: parent
40 ToolButton {
41 text: qsTr("‹")
42 onClicked: stack.pop()
43 }
44 Label {
45 text: "Title"
46 elide: Label.ElideRight
47 horizontalAlignment: Qt.AlignHCenter
48 verticalAlignment: Qt.AlignVCenter
49 Layout.fillWidth: true
50 }
51 ToolButton {
52 text: qsTr("⋮")
53 onClicked: menu.open()
54 }
55 }
56 }
57
58 StackView {
59 id: stack
60 anchors.fill: parent
61 }
62 }
63 \endcode
64
65 \sa ApplicationWindow, ToolButton, {Customizing ToolBar}, {Container Controls}
66*/
67
69{
70public:
71 QPalette defaultPalette() const override { return QQuickTheme::palette(QQuickTheme::ToolBar); }
72
73 bool handlePress(const QPointF &point, ulong timestamp) override;
74
76};
77
78QQuickToolBar::QQuickToolBar(QQuickItem *parent)
79 : QQuickPane(*(new QQuickToolBarPrivate), parent)
80{
81}
82
83/*!
84 \qmlproperty enumeration QtQuick.Controls::ToolBar::position
85
86 This property holds the position of the toolbar.
87
88 \note If the toolbar is assigned as a header or footer of \l ApplicationWindow
89 or \l Page, the appropriate position is set automatically.
90
91 Possible values:
92 \value ToolBar.Header The toolbar is at the top, as a window or page header.
93 \value ToolBar.Footer The toolbar is at the bottom, as a window or page footer.
94
95 The default value is style-specific.
96
97 \sa ApplicationWindow::header, ApplicationWindow::footer, Page::header, Page::footer
98*/
99QQuickToolBar::Position QQuickToolBar::position() const
100{
101 Q_D(const QQuickToolBar);
102 return d->position;
103}
104
105void QQuickToolBar::setPosition(Position position)
106{
107 Q_D(QQuickToolBar);
108 if (d->position == position)
109 return;
110
111 d->position = position;
112 emit positionChanged();
113}
114
115QFont QQuickToolBar::defaultFont() const
116{
117 return QQuickTheme::font(QQuickTheme::ToolBar);
118}
119
120#if QT_CONFIG(accessibility)
121QAccessible::Role QQuickToolBar::accessibleRole() const
122{
123 return QAccessible::ToolBar;
124}
125#endif
126
127bool QQuickToolBarPrivate::handlePress(const QPointF &point, ulong timestamp)
128{
129 if (position == QQuickToolBar::Header && window && parent == window
130 && window->flags() & (Qt::ExpandedClientAreaHint | Qt::NoTitleBarBackgroundHint)
131 && qobject_cast<QQuickApplicationWindow*>(window)) {
132 if (window->startSystemMove())
133 return true;
134 }
135
136 return QQuickPanePrivate::handlePress(point, timestamp);
137}
138
139QT_END_NAMESPACE
140
141#include "moc_qquicktoolbar_p.cpp"
Container for context-sensitive controls.
QPalette defaultPalette() const override
bool handlePress(const QPointF &point, ulong timestamp) override