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