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
container.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\class QDesignerContainerExtension
6
\brief The QDesignerContainerExtension class allows you to add pages to
7
a custom multi-page container in \QD's workspace.
8
\inmodule QtDesigner
9
10
\image containerextension-example.webp
11
12
QDesignerContainerExtension provide an interface for creating
13
custom container extensions. A container extension consists of a
14
collection of functions that \QD needs to manage a multi-page
15
container plugin, and a list of the container's pages.
16
17
\warning This is \e not an extension for container plugins in
18
general, only custom \e multi-page containers.
19
20
To create a container extension, your extension class must inherit
21
from both QObject and QDesignerContainerExtension. For example:
22
23
\snippet plugins/doc_src_qtdesigner.cpp 6
24
25
Since we are implementing an interface, we must ensure that it's
26
made known to the meta object system using the Q_INTERFACES()
27
macro. This enables \QD to use the qobject_cast() function to
28
query for supported interfaces using nothing but a QObject
29
pointer.
30
31
You must reimplement several functions to enable \QD to manage a
32
custom multi-page container widget: \QD uses count() to keep track
33
of the number pages in your container, widget() to return the page
34
at a given index in the list of the container's pages, and
35
currentIndex() to return the list index of the selected page. \QD
36
uses the addWidget() function to add a given page to the
37
container, expecting it to be appended to the list of pages, while
38
it expects the insertWidget() function to add a given page to the
39
container by inserting it at a given index.
40
41
In \QD the extensions are not created until they are
42
required. For that reason you must also create a
43
QExtensionFactory, i.e a class that is able to make an instance of
44
your extension, and register it using \QD's \l
45
{QExtensionManager}{extension manager}.
46
47
When a container extension is required, \QD's \l
48
{QExtensionManager}{extension manager} will run through all its
49
registered factories calling QExtensionFactory::createExtension()
50
for each until the first one that is able to create a container
51
extension, is found. This factory will then create the extension
52
for the plugin.
53
54
There are four available types of extensions in \QD:
55
QDesignerContainerExtension , QDesignerMemberSheetExtension,
56
QDesignerPropertySheetExtension and QDesignerTaskMenuExtension.
57
\QD's behavior is the same whether the requested extension is
58
associated with a multi page container, a member sheet, a property
59
sheet or a task menu.
60
61
The QExtensionFactory class provides a standard extension factory,
62
and can also be used as an interface for custom extension
63
factories. You can either create a new QExtensionFactory and
64
reimplement the QExtensionFactory::createExtension() function. For
65
example:
66
67
\snippet plugins/doc_src_qtdesigner.cpp 7
68
69
Or you can use an existing factory, expanding the
70
QExtensionFactory::createExtension() function to make the factory
71
able to create a container extension as well. For example:
72
73
\snippet plugins/doc_src_qtdesigner.cpp 8
74
75
For a complete example using the QDesignerContainerExtension
76
class, see the \l {containerextension}{Container
77
Extension example}. The example shows how to create a custom
78
multi-page plugin for \QD.
79
80
\sa QExtensionFactory, QExtensionManager, {Creating Custom Widget
81
Extensions}
82
*/
83
84
/*!
85
\fn QDesignerContainerExtension::~QDesignerContainerExtension()
86
87
Destroys the extension.
88
*/
89
90
/*!
91
\fn int QDesignerContainerExtension::count() const
92
93
Returns the number of pages in the container.
94
*/
95
96
/*!
97
\fn QWidget *QDesignerContainerExtension::widget(int index) const
98
99
Returns the page at the given \a index in the extension's list of
100
pages.
101
102
\sa addWidget(), insertWidget()
103
*/
104
105
/*!
106
\fn int QDesignerContainerExtension::currentIndex() const
107
108
Returns the index of the currently selected page in the
109
container.
110
111
\sa setCurrentIndex()
112
*/
113
114
/*!
115
\fn void QDesignerContainerExtension::setCurrentIndex(int index)
116
117
Sets the currently selected page in the container to be the
118
page at the given \a index in the extension's list of pages.
119
120
\sa currentIndex()
121
*/
122
123
/*!
124
\fn void QDesignerContainerExtension::addWidget(QWidget *page)
125
126
Adds the given \a page to the container by appending it to the
127
extension's list of pages.
128
129
\sa insertWidget(), remove(), widget()
130
*/
131
132
/*!
133
\fn void QDesignerContainerExtension::insertWidget(int index, QWidget *page)
134
135
Adds the given \a page to the container by inserting it at the
136
given \a index in the extension's list of pages.
137
138
\sa addWidget(), remove(), widget()
139
*/
140
141
/*!
142
\fn void QDesignerContainerExtension::remove(int index)
143
144
Removes the page at the given \a index from the extension's list
145
of pages.
146
147
\sa addWidget(), insertWidget()
148
*/
149
150
/*!
151
\fn bool QDesignerContainerExtension::canAddWidget() const
152
153
Returns whether a widget can be added. This determines whether
154
the context menu options to add or insert pages are enabled.
155
156
This should return false for containers that have a single, fixed
157
page, for example QScrollArea or QDockWidget.
158
159
\since 5.0
160
\sa addWidget(), canRemove()
161
*/
162
163
/*!
164
\fn bool QDesignerContainerExtension::canRemove(int index) const
165
166
Returns whether the widget at the given \a index can be removed.
167
This determines whether the context menu option to remove the current
168
page is enabled.
169
170
This should return false for containers that have a single, fixed
171
page, for example QScrollArea or QDockWidget.
172
173
\since 5.0
174
\sa remove(), canAddWidget()
175
*/
qttools
src
designer
src
lib
sdk
container.qdoc
Generated on Sat Sep 21 2024 01:06:10 for Qt by
1.12.0