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  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QWidgetFactory Class Reference

The QWidgetFactory class provides for the dynamic creation of widgets from Qt Designer .ui files. More...

#include <qwidgetfactory.h>

List of all member functions.

Public Members

Static Public Members

  • QWidget * create ( const QString & uiFile, QObject * connector = 0, QWidget * parent = 0, const char * name = 0 )
  • QWidget * create ( QIODevice * dev, QObject * connector = 0, QWidget * parent = 0, const char * name = 0 )
  • void addWidgetFactory ( QWidgetFactory * factory )
  • void loadImages ( const QString & dir )
  • QStringList widgets ()
  • bool supportsWidget ( const QString & widget )

Detailed Description

The QWidgetFactory class provides for the dynamic creation of widgets from Qt Designer .ui files.

This class basically offers two things:

  • Dynamically creating widgets from Qt Designer user interface description files. You can do this using the static function QWidgetFactory::create(). This function also performs signal and slot connections, tab ordering, etc., as defined in the .ui file, and returns the top-level widget in the .ui file. After creating the widget you can use QObject::child() and QObject::queryList() to access child widgets of this returned widget.

  • Adding additional widget factories to be able to create custom widgets. See createWidget() for details.

This class is not included in the Qt library itself. To use it you must link against libqui.so (Unix) or qui.lib (Windows), which is built into INSTALL/lib if you built Qt Designer (INSTALL is the directory where Qt is installed ).

If you create a QMainWindow using a QWidgetFactory, be aware that it already has a central widget. Therefore, you need to delete this one before setting another one.

See the "Creating Dynamic Dialogs from .ui Files" section of the Qt Designer manual for an example. See also the QWidgetPlugin class and the Plugins documentation.


Member Function Documentation

QWidgetFactory::QWidgetFactory ()

Constructs a QWidgetFactory.

QWidgetFactory::~QWidgetFactory () [virtual]

Destructor.

void QWidgetFactory::addWidgetFactory ( QWidgetFactory * factory ) [static]

Installs a widget factory factory, which normally contains additional widgets that can then be created using a QWidgetFactory. See createWidget() for further details.

QWidget * QWidgetFactory::create ( const QString & uiFile, QObject * connector = 0, QWidget * parent = 0, const char * name = 0 ) [static]

Loads the Qt Designer user interface description file uiFile and returns the top-level widget in that description. parent and name are passed to the constructor of the top-level widget.

This function also performs signal and slot connections, tab ordering, etc., as described in the .ui file. In Qt Designer it is possible to add custom slots to a form and connect to them. If you want these connections to be made, you must create a class derived from QObject, which implements all these slots. Then pass an instance of the object as connector to this function. If you do this, the connections to the custom slots will be done using the connector as slot.

If something fails, 0 is returned.

The ownership of the returned widget is passed to the caller.

QWidget * QWidgetFactory::create ( QIODevice * dev, QObject * connector = 0, QWidget * parent = 0, const char * name = 0 ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Loads the user interface description from device dev.

QWidget * QWidgetFactory::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.

  2. 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.

void QWidgetFactory::loadImages ( const QString & dir ) [static]

If you use a pixmap collection (which is the default for new projects) rather than saving the pixmaps within the .ui XML file, you must load the pixmap collection. QWidgetFactory looks in the default QMimeSourceFactory for the pixmaps. Either add it there manually, or call this function and specify the directory where the images can be found, as dir. This is normally the directory called images in the project's directory.

bool QWidgetFactory::supportsWidget ( const QString & widget ) [static]

Returns TRUE if the widget factory can create the specified widget; otherwise returns FALSE.

QStringList QWidgetFactory::widgets () [static]

Returns the names of the widgets this factory can create.

This file is part of the Qt toolkit. Copyright © 1995-2005 Trolltech. All Rights Reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. 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
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Introduction

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 3.3
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