Reputation: 11140
I have MyCustomWidget in a namespace MyNameSpace
namespace MyNameSpace{
class MyCustomWidget : public QWidget{
};
}
How do I promote a QWidget to MyCustomWidget in my UI form? It doesn't seem to accept a custom namespace.
Upvotes: 8
Views: 3409
Reputation: 7170
My custom plugin works good using the following code. In this example, the namespace is not only used in the plugin but also in the class which inherits the plugin.
Header for the plugin --- it could 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 that plugin
Implement the class as usual, but the following methods must take into account 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) {}
};
}
Upvotes: 1
Reputation: 4492
Type the name of the class with the namespace included: My::PushButton
. It works. Note that:
my_pushbutton.h
. Change it if it is wrong.Upvotes: 14