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.
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.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) {}
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With