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

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

Версия от 14:39, 12 января 2009; Root (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

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

Image:trolltech-logo.png

Содержание

[править] 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. Далее...

 #include <QUiLoader>

Inherits QObject.

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

  • 29 открытых функций, унаследованных от QObject

[править] Дополнительные унаследованные члены

  • 1 свойство, унаследованное от QObject
  • 1 открытый слот, унаследованный от QObject
  • 1 сигнал, унаследованный от QObject
  • 5 статических открытых членов, унаследованных от QObject
  • 7 защищенных функций, унаследованных от QObject

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

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 customize of creating an user interface by deriving your own loader class.

If you have a custom component or an application that embeds 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. Пример:

 MyWidget::MyWidget(QWidget *parent)
     : QWidget(parent)
 {
     QUiLoader loader;
     QFile file(":/forms/myform.ui");
     file.open(QFile::ReadOnly);
     QWidget *myWidget = loader.load(&amp;file, this);
     file.close();
 
     QVBoxLayout *layout = new QVBoxLayout;
     layout->addWidget(myWidget);
     setLayout(layout);
 }

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

 <!DOCTYPE RCC><RCC version="1.0">
 <qresource prefix="/forms">
 <file>myform.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. Пример:

 QWidget *loadCustomWidget(QWidget *parent)
 {
     QUiLoader loader;
     QWidget *myWidget;
 
     QStringList availableWidgets = loader.availableWidgets();
 
     if (availableWidgets.contains("AnalogClock"))
         myWidget = loader.createWidget("AnalogClock", parent);
 
     return myWidget;
 }

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.


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

[править]
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 in the process of constructing a 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().

[править]
void QUiLoader::setWorkingDirectory ( const QDir & dir )

Sets the working directory of the loader to dir. The loader looks for other resources, such as icons and resource files, in paths relative to this directory.

See also workingDirectory().

[править]
QDir QUiLoader::workingDirectory () const

Returns the working directory of the loader.

See also setWorkingDirectory().



Copyright © 2007 Trolltech Trademarks
Qt 4.3.2