Notice: Undefined offset: 1 in /home/developpez/www/developpez-com/upload/qt/doc/redir.php on line 39 Qt 4.7: QDesignerCustomWidgetInterface Class Reference
Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QDesignerCustomWidgetInterface Class Reference

The QDesignerCustomWidgetInterface class enables Qt Designer to access and construct custom widgets. More...

 #include <QDesignerCustomWidgetInterface>

Public Functions

virtual ~QDesignerCustomWidgetInterface ()
virtual QString codeTemplate () const
virtual QWidget * createWidget ( QWidget * parent ) = 0
virtual QString domXml () const
virtual QString group () const = 0
virtual QIcon icon () const = 0
virtual QString includeFile () const = 0
virtual void initialize ( QDesignerFormEditorInterface * formEditor )
virtual bool isContainer () const = 0
virtual bool isInitialized () const
virtual QString name () const = 0
virtual QString toolTip () const = 0
virtual QString whatsThis () const = 0

Macros

QDESIGNER_WIDGET_EXPORT

Detailed Description

The QDesignerCustomWidgetInterface class enables Qt Designer to access and construct custom widgets.

QDesignerCustomWidgetInterface provides a custom widget with an interface. The class contains a set of functions that must be subclassed to return basic information about the widget, such as its class name and the name of its header file. Other functions must be implemented to initialize the plugin when it is loaded, and to construct instances of the custom widget for Qt Designer to use.

When implementing a custom widget you must subclass QDesignerCustomWidgetInterface to expose your widget to Qt Designer. For example, this is the declaration for the plugin used in the Custom Widget Plugin example that enables an analog clock custom widget to be used by Qt Designer:

 class AnalogClockPlugin : public QObject, public QDesignerCustomWidgetInterface
 {
     Q_OBJECT
     Q_INTERFACES(QDesignerCustomWidgetInterface)

 public:
     AnalogClockPlugin(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;
 };

Note that the only part of the class definition that is specific to this particular custom widget is the class name. In addition, since we are implementing an interface, we must ensure that it's made known to the meta object system using the Q_INTERFACES() macro. This enables Qt Designer to use the qobject_cast() function to query for supported interfaces using nothing but a QObject pointer.

After Qt Designer loads a custom widget plugin, it calls the interface's initialize() function to enable it to set up any resources that it may need. This function is called with a QDesignerFormEditorInterface parameter that provides the plugin with a gateway to all of Qt Designer's API.

Qt Designer constructs instances of the custom widget by calling the plugin's createWidget() function with a suitable parent widget. Plugins must construct and return an instance of a custom widget with the specified parent widget.

In the implementation of the class you must remember to export your custom widget plugin to Qt Designer using the Q_EXPORT_PLUGIN2() macro. For example, if a library called libcustomwidgetplugin.so (on Unix) or libcustomwidget.dll (on Windows) contains a widget class called MyCustomWidget, we can export it by adding the following line to the file containing the plugin implementation:

 Q_EXPORT_PLUGIN2(customwidgetplugin, MyCustomWidget)

This macro ensures that Qt Designer can access and construct the custom widget. Without this macro, there is no way for Qt Designer to use it.

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.

Warning: If your custom widget plugin contains QVariant properties, be aware that only the following types are supported:

For a complete example using the QDesignerCustomWidgetInterface class, see the Custom Widget Example. The example shows how to create a custom widget plugin for Qt Designer.

See also QDesignerCustomWidgetCollectionInterface and Creating Custom Widgets for Qt Designer.

Member Function Documentation

QDesignerCustomWidgetInterface::~QDesignerCustomWidgetInterface () [virtual]

Destroys the custom widget interface.

QString QDesignerCustomWidgetInterface::codeTemplate () const [virtual]

This function is reserved for future use by Qt Designer.

QWidget * QDesignerCustomWidgetInterface::createWidget ( QWidget * parent ) [pure virtual]

Returns a new instance of the custom widget, with the given parent.

QString QDesignerCustomWidgetInterface::domXml () const [virtual]

Returns the XML that is used to describe the custom widget's properties to Qt Designer.

QString QDesignerCustomWidgetInterface::group () const [pure virtual]

Returns the name of the group to which the custom widget belongs.

QIcon QDesignerCustomWidgetInterface::icon () const [pure virtual]

Returns the icon used to represent the custom widget in Qt Designer's widget box.

QString QDesignerCustomWidgetInterface::includeFile () const [pure virtual]

Returns the path to the include file that uic uses when creating code for the custom widget.

void QDesignerCustomWidgetInterface::initialize ( QDesignerFormEditorInterface * formEditor ) [virtual]

Initializes the widget for use with the specified formEditor interface.

See also isInitialized().

bool QDesignerCustomWidgetInterface::isContainer () const [pure virtual]

Returns true if the custom widget is intended to be used as a container; otherwise returns false.

Most custom widgets are not used to hold other widgets, so their implementations of this function will return false, but custom containers will return true to ensure that they behave correctly in Qt Designer.

bool QDesignerCustomWidgetInterface::isInitialized () const [virtual]

Returns true if the widget has been initialized; otherwise returns false.

See also initialize().

QString QDesignerCustomWidgetInterface::name () const [pure virtual]

Returns the class name of the custom widget supplied by the interface.

The name returned must be identical to the class name used for the custom widget.

QString QDesignerCustomWidgetInterface::toolTip () const [pure virtual]

Returns a short description of the widget that can be used by Qt Designer in a tool tip.

QString QDesignerCustomWidgetInterface::whatsThis () const [pure virtual]

Returns a description of the widget that can be used by Qt Designer in "What's This?" help for the widget.

Macro Documentation

QDESIGNER_WIDGET_EXPORT

This macro is used when defining custom widgets to ensure that they are correctly exported from plugins for use with Qt Designer.

On some platforms, the symbols required by Qt Designer to create new widgets are removed from plugins by the build system, making them unusable. Using this macro ensures that the symbols are retained on those platforms, and has no side effects on other platforms.

For example, the World Time Clock Plugin example exports a custom widget class with the following declaration:

 class QDESIGNER_WIDGET_EXPORT WorldTimeClock : public QWidget
 {
     Q_OBJECT
     ...
 };

This function was introduced in Qt 4.1.

See also Creating Custom Widgets for Qt Designer.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

La création de colonnes dans une ListView en QML

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web