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  ·  Modules  ·  Fonctions  · 

QUiLoader Class Reference
[QtUiTools module]

The QUiLoader class allows standalone applications dynamically create user interfaces at run-time using the information stored in .ui files or specified plugin paths. More...

#include <QUiLoader>

Inherits QObject.

Public Functions

  • QUiLoader ( QObject * parent = 0 )
  • virtual ~QUiLoader ()
  • void addPluginPath ( const QString & path )
  • QStringList availableWidgets () const
  • virtual QAction * createAction ( QObject * parent = 0, const QString & name = QString() )
  • virtual QActionGroup * createActionGroup ( QObject * parent = 0, const QString & name = QString() )
  • virtual QLayout * createLayout ( const QString & className, QObject * parent = 0, const QString & name = QString() )
  • virtual QWidget * createWidget ( const QString & className, QWidget * parent = 0, const QString & name = QString() )
  • QWidget * load ( QIODevice * device, QWidget * parentWidget = 0 )
  • QStringList pluginPaths () const
  • 28 public functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject
  • 4 static public members inherited from QObject
  • 7 protected functions inherited from QObject

Detailed Description

The QUiLoader class allows standalone applications dynamically create user interfaces at run-time using the information stored in .ui files or specified plugin paths.

In addition, you can intervene the process of creating an user interface by deriving your own loader class.

If you have a custom component or application that embed Qt Designer, you can also use the QFormBuilder class provided by the QtDesigner module to create user interfaces from .ui files.

The QUiLoader class provides a collection of functions that allows you to create widgets based on the information stored in .ui files (created with Qt Designer) or available in the specified plugin paths. The specified plugin paths can be retrieved using the pluginPaths() function. You can retrieve the contents of an .ui file using the load() function. For example:

    MyForm::MyForm(QWidget *parent)
        : QWidget(parent)
    {
        QUiLoader loader;
        QFile file(":/forms/mywidget.ui");
        file.open(QFile::ReadOnly);
        QWidget *myWidget = loader.load(&file, this);
        file.close();

        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(myWidget);
        setLayout(layout);
    }

By including the user interface in the form's resources (myForm.grc), we ensure that it will be present at run-time:

        <!DOCTYPE RCC><RCC version="1.0">
        <qresource prefix="/forms">
        <file>mywidget.ui</file>
        </qresource>
        </RCC>

The availableWidgets() function returns a QStringList with the class names of the widgets available in the specified plugin paths. You can create any of these widgets using the createWidget() function. For example:

        QUiLoader loader;
        MyCustomWidget *myWidget;
        QWidget parent;

        QStringList availableWidgets = loader.availableWidgets();

        if (availableWidgets.contains("MyCustomWidget"))
            myWidget = qobject_cast<MyCustomWidget *>loader.createWidget("MyCustomWidget",
                                                                          parent)
        }

You can make a custom widget available to the loader using the addPluginPath() function, and you can remove all the available widgets by calling the clearPluginPaths() function.

The createAction(), createActionGroup(), createLayout() and createWidget() functions are used internally by the QUiLoader class whenever it has to create an action, action group, layout or widget respectively. For that reason, you can subclass the QUiLoader class and reimplement these functions to intervene the process of constructing an user interface. For example, you might want to create a list of the actions created when loading a form or creating a custom widget.

For a complete example using the QUiLoader class, see the Calculator Builder example.

See also QtUiTools and QFormBuilder.


Member Function Documentation

QUiLoader::QUiLoader ( QObject * parent = 0 )

Creates a form loader with the given parent.

QUiLoader::~QUiLoader ()   [virtual]

Destroys the loader.

void QUiLoader::addPluginPath ( const QString & path )

Adds the given path to the list of paths the loader searches when locating plugins.

See also pluginPaths() and clearPluginPaths().

QStringList QUiLoader::availableWidgets () const

Returns a list naming the available widgets that can be built using the createWidget() function, i.e all the widgets specified within the given plugin paths.

See also pluginPaths() and createWidget().

void QUiLoader::clearPluginPaths ()

Clears the list of paths the loader searches when locating plugins.

See also addPluginPath() and pluginPaths().

QAction * QUiLoader::createAction ( QObject * parent = 0, const QString & name = QString() )   [virtual]

Creates a new action with the given parent and name.

The function is used internally by the QUiLoader class whenever it has to create an action. For that reason, you can subclass the QUiLoader class and reimplement this function to intervene the process of constructing an user interface or widget.

See also createActionGroup(), createWidget(), and load().

QActionGroup * QUiLoader::createActionGroup ( QObject * parent = 0, const QString & name = QString() )   [virtual]

Creates a new action group with the given parent and name.

The function is used internally by the QUiLoader class whenever it has to create an action group. For that reason, you can subclass the QUiLoader class and reimplement this function to intervene the process of constructing an user interface or widget.

See also createAction(), createWidget(), and load().

QLayout * QUiLoader::createLayout ( const QString & className, QObject * parent = 0, const QString & name = QString() )   [virtual]

Creates a new layout with the given parent and name using the class specified by className.

The function is used internally by the QUiLoader class whenever it has to create a layout. For that reason, you can subclass the QUiLoader class and reimplement this function to intervene the process of constructing an user interface or widget.

See also createWidget() and load().

QWidget * QUiLoader::createWidget ( const QString & className, QWidget * parent = 0, const QString & name = QString() )   [virtual]

Creates a new widget with the given parent and name using the class specified by className. You can use this function to create any of the widgets returned by the availableWidgets() function.

The function is also used internally by the QUiLoader class whenever it has to create a widget. For that reason, you can subclass the QUiLoader class and reimplement this function to intervene the process of constructing an user interface or widget.

See also availableWidgets() and load().

QWidget * QUiLoader::load ( QIODevice * device, QWidget * parentWidget = 0 )

Loads a form from the given device and creates a new widget with the given parentWidget to hold its contents.

See also createWidget().

QStringList QUiLoader::pluginPaths () const

Returns a list naming the paths the loader searches when locating custom widget plugins.

See also addPluginPath() and clearPluginPaths().

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

Utiliser QML et QtWebKit avec PySide

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