Qt:Документация 4.3.2/qdesignercustomwidgetcollectioninterface

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QDesignerCustomWidgetCollectionInterface Class Reference
[ QtDesigner module]

The QDesignerCustomWidgetCollectionInterface class allows you to include several custom widgets in one single library. Далее...

 #include <QDesignerCustomWidgetCollectionInterface>

[править] Открытые функции


[править] Подробное описание

The QDesignerCustomWidgetCollectionInterface class allows you to include several custom widgets in one single library.

When implementing a custom widget plugin, you build it as a separate library. If you want to include several custom widget plugins in the same library, you must in addition subclass QDesignerCustomWidgetCollectionInterface.

QDesignerCustomWidgetCollectionInterface contains one single function returning a list of the collection's QDesignerCustomWidgetInterface objects. For example, if you have several custom widgets CustomWidgetOne, CustomWidgetTwo and CustomWidgetThree, the class definition may look like this:

 #include customwidgetoneinterface.h
 #include customwidgettwointerface.h
 #include customwidgetthreeinterface.h
 
 #include <QtDesigner/QtDesigner>
 #include <QtCore/qplugin.h>
 
 class MyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
 {
     Q_OBJECT
     Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
 
 public:
     MyCustomWidgets(QObject *parent = 0);
 
     virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
 
 private:
     QList<QDesignerCustomWidgetInterface*> widgets;
 };

In the class constructor you add the interfaces to your custom widgets to the list which you return in the customWidgets() function:

 MyCustomWidgets::MyCustomWidgets(QObject *parent)
         : QObject(parent)
 {
     widgets.append(new CustomWidgetOneInterface(this));
     widgets.append(new CustomWidgetTwoInterface(this));
     widgets.append(new CustomWidgetThreeInterface(this));
 }
 
 QList<QDesignerCustomWidgetInterface*> MyCustomWidgets::customWidgets() const
 {
     return widgets;
 }
 
 Q_EXPORT_PLUGIN2(MyCustomWidgets)

Note that instead of exporting each custom widget plugin using the Q_EXPORT_PLUGIN2() macro, you export the entire collection. The Q_EXPORT_PLUGIN2() macro ensures that Qt Designer can access and construct the custom widgets. Without this macro, there is no way for Qt Designer to use them.

See also QDesignerCustomWidgetInterface and Creating Custom Widgets for Qt Designer.


[править] Описание функций-членов

[править]
QDesignerCustomWidgetCollectionInterface::~QDesignerCustomWidgetCollectionInterface () [virtual]

Destroys the custom widget collection interface.

[править]
QList< QDesignerCustomWidgetInterface *> QDesignerCustomWidgetCollectionInterface::customWidgets () const [pure virtual]

Returns a list of interfaces to the collection's custom widgets.



Copyright © 2007 Trolltech Trademarks
Qt 4.3.2