Eneboo - Documentación para desarrolladores
|
#include <widgetfactory.h>
Métodos públicos | |
CustomWidgetFactory () | |
QWidget * | createWidget (const QString &className, QWidget *parent, const char *name) const |
CustomWidgetFactory::CustomWidgetFactory | ( | ) |
QWidget * CustomWidgetFactory::createWidget | ( | const QString & | className, |
QWidget * | parent, | ||
const char * | name | ||
) | const [virtual] |
Creates a widget of the type className passing parent and name to its constructor.
If className is a widget in the Qt library, it is directly created by this function. If the widget isn't in the Qt library, each of the installed widget plugins is asked, in turn, to create the widget. As soon as a plugin says it can create the widget it is asked to do so. It may occur that none of the plugins can create the widget, in which case each installed widget factory is asked to create the widget (see addWidgetFactory()). If the widget cannot be created by any of these means, 0 is returned.
If you have a custom widget, and want it to be created using the widget factory, there are two approaches you can use:
1
Write a widget plugin. This allows you to use the widget in {Qt Designer} and in this QWidgetFactory. See the widget plugin documentation for further details. (See the "Creating Custom Widgets with Plugins" section of the Qt Designer manual for an example.
Subclass QWidgetFactory. Then reimplement this function to create and return an instance of your custom widget if className equals the name of your widget, otherwise return 0. Then at the beginning of your program where you want to use the widget factory to create widgets do a:
QWidgetFactory::addWidgetFactory( new MyWidgetFactory );
where MyWidgetFactory is your QWidgetFactory subclass.
Reimplementado de QWidgetFactory.