Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It feels like a bit home-worky, but you would need something like the code below. I have never tested it myself, and I have not even tried to compile it. However, this should be a good starting point to begin with.</p> <h3>dynamicpropertyplugin.h</h3> <pre><code> #ifndef DYNAMICPROPERTYPLUGIN_H #define DYNAMICPROPERTYPLUGIN_H #include &lt;QDesignerCustomWidgetInterface&gt; class QIcon; class QWidget; class DynamicPropertyPlugin : public QObject, public QDesignerCustomWidgetInterface { Q_OBJECT Q_INTERFACES(QDesignerCustomWidgetInterface) public: DynamicPropertyPlugin(QObject *parent = 0); QString name() const; QString group() const; QString toolTip() const; QString whatsThis() const; QString includeFile() const; QIcon icon() const; bool isContainer() const; QWidget *createWidget(QWidget *parent); bool isInitialized() const; void initialize(QDesignerFormEditorInterface *formEditor); QString domXml() const; private: bool initialized; }; #endif </code></pre> <h3>dynamicpropertyextension.h</h3> <pre><code>class DynamicPropertyExtension : public QObject, public QDesignerDynamicPropertySheetExtension { Q_OBJECT Q_INTERFACES(QDesignerDynamicPropertySheetExtension) public: DynamicPropertyExtension(QObject *parent = 0); int addDynamicProperty(const QString &amp; propertyName, const QVariant &amp; value); bool canAddDynamicProperty(const QString &amp; propertyName) const; bool dynamicPropertiesAllowed() const; bool isDynamicProperty(int index) const; bool removeDynamicProperty(int index); }; </code></pre> <h3>dynamicpropertyplugin.cpp</h3> <pre><code>#include &lt;QtDesigner&gt; #include &lt;QtGui&gt; #include &lt;QtPlugin&gt; #include "dynamicproperty.h" #include "dynamicpropertyplugin.h" #include "dynamicpropertyextension.h" DynamicPropertyPlugin::DynamicPropertyPlugin(QObject *parent) : QObject(parent) { initialized = false; } QString DynamicPropertyPlugin::name() const { return "DynamicProperty"; } QString DynamicPropertyPlugin::group() const { return "Display Widgets [Examples]"; } QString DynamicPropertyPlugin::toolTip() const { return ""; } QString DynamicPropertyPlugin::whatsThis() const { return ""; } QString DynamicPropertyPlugin::includeFile() const { return "dynamicproperty.h"; } QIcon DynamicPropertyPlugin::icon() const { return QIcon(); } bool DynamicPropertyPlugin::isContainer() const { return false; } QWidget *DynamicPropertyPlugin::createWidget(QWidget *parent) { DynamicProperty *dynamicProperty = new DynamicProperty(parent); dynamicProperty-&gt;setState("-X-XO----"); return dynamicProperty; } bool DynamicPropertyPlugin::isInitialized() const { return initialized; } void DynamicPropertyPlugin::initialize(QDesignerFormEditorInterface *formEditor) { if (initialized) return; QExtensionManager *manager = designerFormEditorInterface-&gt;extensionManager(); Q_ASSERT(manager != 0); manager-&gt;registerExtensions(new DynamicPropertyExtensionFactory(manager), Q_TYPEID(QDesignerDynamicPropertySheetExtension)); initialized = true; } QString DynamicPropertyPlugin::domXml() const { return QLatin1String("\ &lt;ui language=\"c++\"&gt;\ &lt;widget class=\"DynamicProperty\" name=\"dynamicProperty\"/&gt;\ &lt;customwidgets&gt;\ &lt;customwidget&gt;\ &lt;class&gt;DynamicProperty&lt;/class&gt;\ &lt;propertyspecifications&gt;\ &lt;stringpropertyspecification name=\"state\" notr=\"true\" type=\"singleline\"/&gt;\ &lt;/propertyspecifications&gt;\ &lt;/customwidget&gt;\ &lt;/customwidgets&gt;\ &lt;/ui&gt;"); } Q_EXPORT_PLUGIN2(dynamicpropertyextension, DynamicPropertyPlugin </code></pre> <h3>dynamicpropertyextension.h</h3> <pre><code> #ifndef DYNAMICPROPERTYEXTENSION_H #define DYNAMICPROPERTYEXTENSION_H #include &lt;QDesignerDynamicPropertySheetExtension&gt; #include &lt;QExtensionFactory&gt; class QAction; class QExtensionManager; class DynamicProperty; class DynamicPropertyExtension : public QObject, public QDesignerDynamicPropertySheetExtension { Q_OBJECT Q_INTERFACES(QDesignerDynamicPropertySheetExtension) public: DynamicPropertyExtension(DynamicPropertyExtenion *tic, QObject *parent); QAction *preferredEditAction() const; QList&lt;QAction *&gt; taskActions() const; private slots: void editState(); private: QAction *editStateAction; DynamicProperty *dynamicProperty; }; class DynamicPropertyExtensionFactory : public QExtensionFactory { Q_OBJECT public: DynamicPropertyExtensionFactory(QExtensionManager *parent = 0); protected: QObject *createExtension(QObject *object, const QString &amp;iid, QObject *parent) const; }; #endif </code></pre> <h3>dynamicpropertyextension.cpp</h3> <pre><code>#include &lt;QtDesigner&gt; #include &lt;QtGui&gt; #include "dynamicproperty.h" #include "dynamicpropertydialog.h" #include "dynamicpropertyextension.h" DynamicPropertyExtension::DynamicPropertyExtension(DynamicProperty *dp, QObject *parent) : QObject(parent) { dynamicProperty = dp; editStateAction = new QAction(tr("Edit State..."), this); connect(editStateAction, SIGNAL(triggered()), this, SLOT(editState())); } void DynamicPropertyExtension::editState() { DynamicPropertyDialog dialog(ticTacToe); dialog.exec(); } QAction *DynamicPropertyExtension::preferredEditAction() const { return editStateAction; } QList&lt;QAction *&gt; DynamicPropertyExtension::taskActions() const { QList&lt;QAction *&gt; list; list.append(editStateAction); return list; } DynamicPropertyExtensionFactory::DynamicPropertyExtensionFactory(QExtensionManager *parent) : QExtensionFactory(parent) { } QObject *DynamicPropertyExtensionFactory::createExtension(QObject *object, const QString &amp;iid, QObject *parent) const { if (iid != Q_TYPEID(QDesignerDynamicPropertySheetExtension)) return 0; if (DynamicProperty *dp = qobject_cast&lt;DynamicProperty*&gt;(object)) return new DynamicPropertyExtension(dp, parent); return 0; } </code></pre> <p>Since it is a designer plugin, you will need to assign the following configuration to qmake in the projet file:</p> <pre><code>CONFIG += designer plugin </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload