Promoting a custom widget in a namespace

I have MyCustomWidget in the MyNameSpace namespace

namespace MyNameSpace{ class MyCustomWidget : public QWidget{ }; } 

How do I promote a QWidget in MyCustomWidget in my user interface form? It does not seem to accept a custom namespace.

+7
c ++ user-interface qt4
source share
2 answers

Enter the name of the class with the namespace enabled: My::PushButton . It works. Note:

  • Qt Designer will try to guess the title name: my_pushbutton.h . Change it if it is wrong.
  • You should check the inclusion paths in your project to determine if the global include for the advanced widget will be included.
+11
source share

My custom plugin works well using the following code. In this example, the namespace is used not only in the plugin, but also in the class that the plugin inherits.

Header for the plugin --- it can be used in QDesigner

 namespace plugin { class MyCustomPlugin: public QObject, public QDesignerCustomWidgetInterface { Q_OBJECT Q_INTERFACES(QDesignerCustomWidgetInterface) public: MyCustomPlugin(QObject *parent = 0); bool isContainer() const; bool isInitialized() const; QIcon icon() const; QString domXml() const; QString group() const; QString includeFile() const; QString name() const; QString toolTip() const; QString whatsThis() const; QWidget *createWidget(QWidget *parent); void initialize(QDesignerFormEditorInterface *core); private: bool initialized; }; } 

cpp file for this plugin

Implement the class as usual, but the following methods should consider the namespace:

 QString MyCustomPlugin::domXml() const { return "<widget class=\"plugin::MyCustomClass\" name=\"mycustomclass\">\n" ... } QString MyCustomPlugin::name() const { return "plugin::MyCustomClass"; } QWidget *MyCustomPlugin::createWidget(QWidget *parent) { return new plugin::MyCustomClass(parent); } Q_EXPORT_PLUGIN2(mycustomplugin, plugin::MyCustomPlugin) 

Mycustomclass

 namespace plugin { class QDESIGNER_WIDGET_EXPORT MyCustomClass: public MyCustomPlugin { Q_OBJECT public: MyCustomClass(QWidget * parent = 0) {} }; } 
+1
source share

All Articles