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
doc_src_qtdesigner.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3// Qt-Security score:significant reason:default
4
5//! [2]
7QExtensionManager manager = formEditor->extensionManager();
8
9memberSheet = qt_extension<QDesignerMemberSheetExtension*>(manager, widget);
10int index = memberSheet->indexOf(setEchoMode);
11memberSheet->setVisible(index, false);
12
13delete memberSheet;
14//! [2]
15
16
17//! [3]
18class MyMemberSheetExtension : public QObject,
19 public QDesignerMemberSheetExtension
20{
21 Q_OBJECT
22 Q_INTERFACES(QDesignerMemberSheetExtension)
23
24public:
25 ...
26}
27//! [3]
28
29
30//! [4]
31QObject *ANewExtensionFactory::createExtension(QObject *object,
32 const QString &iid, QObject *parent) const
33{
34 if (iid != Q_TYPEID(QDesignerMemberSheetExtension))
35 return 0;
36
37 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
38 (object))
39 return new MyMemberSheetExtension(widget, parent);
40
41 return 0;
42}
43//! [4]
44
45
46//! [5]
47QObject *AGeneralExtensionFactory::createExtension(QObject *object,
48 const QString &iid, QObject *parent) const
49{
50 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
51
52 if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
53 return new MyTaskMenuExtension(widget, parent);
54
55 } else if (widget && (iid == Q_TYPEID(QDesignerMemberSheetExtension))) {
56 return new MyMemberSheetExtension(widget, parent);
57
58 } else {
59 return 0;
60 }
61}
62//! [5]
63
64
65//! [6]
68{
69 Q_OBJECT
70 Q_INTERFACES(QDesignerContainerExtension)
71
72public:
74 QObject *parent = 0);
75 int count() const;
76 QWidget *widget(int index) const;
77 int currentIndex() const;
78 void setCurrentIndex(int index);
79 void addWidget(QWidget *widget);
80 void insertWidget(int index, QWidget *widget);
81 void remove(int index);
82
83private:
84 MyCustomWidget *myWidget;
85};
86//! [6]
87
88
89//! [7]
90QObject *ANewExtensionFactory::createExtension(QObject *object,
91 const QString &iid, QObject *parent) const
92{
93 if (iid != Q_TYPEID(QDesignerContainerExtension))
94 return 0;
95
96 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
97 (object))
98 return new MyContainerExtension(widget, parent);
99
100 return 0;
101}
102//! [7]
103
104
105//! [8]
106QObject *AGeneralExtensionFactory::createExtension(QObject *object,
107 const QString &iid, QObject *parent) const
108{
109 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
110
111 if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
112 return new MyTaskMenuExtension(widget, parent);
113
114 } else if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
115 return new MyContainerExtension(widget, parent);
116
117 } else {
118 return 0;
119 }
120}
121//! [8]
122
123
124//! [9]
127{
128 Q_OBJECT
129 Q_INTERFACES(QDesignerTaskMenuExtension)
130
131public:
133
136
137private slots:
138 void mySlot();
139
140private:
141 MyCustomWidget *widget;
142 QAction *myAction;
143};
144//! [9]
145
146
147//! [10]
148QObject *ANewExtensionFactory::createExtension(QObject *object,
149 const QString &iid, QObject *parent) const
150{
151 if (iid != Q_TYPEID(QDesignerTaskMenuExtension))
152 return 0;
153
154 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object))
155 return new MyTaskMenuExtension(widget, parent);
156
157 return 0;
158}
159//! [10]
160
161
162//! [11]
163QObject *AGeneralExtensionFactory::createExtension(QObject *object,
164 const QString &iid, QObject *parent) const
165{
166 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
167
168 if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
169 return new MyContainerExtension(widget, parent);
170
171 } else if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
172 return new MyTaskMenuExtension(widget, parent);
173
174 } else {
175 return 0;
176 }
177}
178//! [11]
179
180
181//! [12]
182#include customwidgetoneinterface.h
183#include customwidgettwointerface.h
184#include customwidgetthreeinterface.h
185
186#include <QtDesigner/qtdesigner.h>
187#include <QtCore/qplugin.h>
188
190{
191 Q_OBJECT
192 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface")
194
195public:
197
199
200private:
201 QList<QDesignerCustomWidgetInterface*> widgets;
202};
203//! [12]
204
205
206//! [13]
207MyCustomWidgets::MyCustomWidgets(QObject *parent)
208 : QObject(parent)
209{
210 widgets.append(new CustomWidgetOneInterface(this));
211 widgets.append(new CustomWidgetTwoInterface(this));
212 widgets.append(new CustomWidgetThreeInterface(this));
213}
214
216{
217 return widgets;
218}
219//! [13]
220
221
222//! [14]
223Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
224//! [14]
225
226
227//! [15]
228QDesignerPropertySheetExtension *propertySheet = nullptr;
229QExtensionManager manager = formEditor->extensionManager();
230
231propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget);
232int index = propertySheet->indexOf(u"margin"_s);
233
234propertySheet->setProperty(index, 10);
235propertySheet->setChanged(index, true);
236
237delete propertySheet;
238//! [15]
239
240
241//! [16]
242class MyPropertySheetExtension : public QObject,
243 public QDesignerPropertySheetExtension
244{
245 Q_OBJECT
246 Q_INTERFACES(QDesignerPropertySheetExtension)
247
248public:
249 ...
250}
251//! [16]
252
253
254//! [17]
255QObject *ANewExtensionFactory::createExtension(QObject *object,
256 const QString &iid, QObject *parent) const
257{
258 if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
259 return 0;
260
261 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
262 (object))
263 return new MyPropertySheetExtension(widget, parent);
264
265 return 0;
266}
267//! [17]
268
269
270//! [18]
271QObject *AGeneralExtensionFactory::createExtension(QObject *object,
272 const QString &iid, QObject *parent) const
273{
274 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
275
276 if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
277 return new MyTaskMenuExtension(widget, parent);
278
279 } else if (widget && (iid == Q_TYPEID(QDesignerPropertySheetExtension))) {
280 return new MyPropertySheetExtension(widget, parent);
281
282 } else {
283 return 0;
284 }
285}
286//! [18]
void setCurrentIndex(int index)
QWidget * widget(int index) const
void addWidget(QWidget *widget)
void insertWidget(int index, QWidget *widget)
void remove(int index)
int currentIndex() const
QList< QDesignerCustomWidgetInterface * > customWidgets() const override
QList< QAction * > taskActions() const
QAction * preferredEditAction() const
QDesignerMemberSheetExtension * memberSheet
[2]
QNetworkAccessManager manager
[0]