Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QUiLoader Class

TheQUiLoader class enables standalone applications to dynamically create user interfaces at run-time using the information stored in UI files or specified in plugin paths.More...

Header:#include <QUiLoader>
Inherits:QObject

Public Functions

QUiLoader(QObject * parent = 0)
virtual~QUiLoader()
voidaddPluginPath(const QString & path)
QStringListavailableLayouts() const
QStringListavailableWidgets() const
voidclearPluginPaths()
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())
boolisLanguageChangeEnabled() const
QWidget *load(QIODevice * device, QWidget * parentWidget = 0)
QStringListpluginPaths() const
voidsetLanguageChangeEnabled(bool enabled)
voidsetWorkingDirectory(const QDir & dir)
QDirworkingDirectory() const
  • 29 public functions inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 1 signal inherited fromQObject
  • 7 static public members inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQUiLoader class enables standalone applications to dynamically create user interfaces at run-time using the information stored in UI files or specified in plugin paths.

In addition, you can customize or create your own user interface by deriving your own loader class.

If you have a custom component or an application that embedsQt Designer, you can also use theQFormBuilder class provided by theQtDesigner module to create user interfaces from UI files.

TheQUiLoader class provides a collection of functions allowing you to create widgets based on the information stored in UI files (created withQt Designer) or available in the specified plugin paths. The specified plugin paths can be retrieved using thepluginPaths() function. Similarly, the contents of a UI file can be retrieved using theload() function. For example:

MyWidget::MyWidget(QWidget*parent)    :QWidget(parent){QUiLoader loader;QFile file(":/forms/myform.ui");    file.open(QFile::ReadOnly);QWidget*myWidget= loader.load(&file,this);    file.close();QVBoxLayout*layout=newQVBoxLayout;    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>

TheavailableWidgets() function returns aQStringList with the class names of the widgets available in the specified plugin paths. To create these widgets, simply use thecreateWidget() function. For example:

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

To make a custom widget available to the loader, you can use theaddPluginPath() function; to remove all available widgets, you can call theclearPluginPaths() function.

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

For a complete example using theQUiLoader class, see theCalculator Builder Example.

See alsoQtUiTools andQFormBuilder.

Member Function Documentation

QUiLoader::QUiLoader(QObject * parent = 0)

Creates a form loader with the givenparent.

[virtual]QUiLoader::~QUiLoader()

Destroys the loader.

void QUiLoader::addPluginPath(constQString & path)

Adds the givenpath to the list of paths in which the loader will search when locating plugins.

See alsopluginPaths() andclearPluginPaths().

QStringList QUiLoader::availableLayouts() const

Returns a list naming all available layouts that can be built using thecreateLayout() function

This function was introduced in Qt 4.5.

See alsocreateLayout().

QStringList QUiLoader::availableWidgets() const

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

See alsopluginPaths() andcreateWidget().

void QUiLoader::clearPluginPaths()

Clears the list of paths in which the loader will search when locating plugins.

See alsoaddPluginPath() andpluginPaths().

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

Creates a new action with the givenparent andname.

The function is also used internally by theQUiLoader class whenever it creates a widget. Hence, you can subclassQUiLoader and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you callQUiLoader's version first.

See alsocreateActionGroup(),createWidget(), andload().

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

Creates a new action group with the givenparent andname.

The function is also used internally by theQUiLoader class whenever it creates a widget. Hence, you can subclassQUiLoader and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you callQUiLoader's version first.

See alsocreateAction(),createWidget(), andload().

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

Creates a new layout with the givenparent andname using the class specified byclassName.

The function is also used internally by theQUiLoader class whenever it creates a widget. Hence, you can subclassQUiLoader and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you callQUiLoader's version first.

See alsocreateWidget() andload().

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

Creates a new widget with the givenparent andname using the class specified byclassName. You can use this function to create any of the widgets returned by theavailableWidgets() function.

The function is also used internally by theQUiLoader class whenever it creates a widget. Hence, you can subclassQUiLoader and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you callQUiLoader's version first.

See alsoavailableWidgets() andload().

bool QUiLoader::isLanguageChangeEnabled() const

Returns true if dynamic retranslation on language change is enabled; returns false otherwise.

This function was introduced in Qt 4.5.

See alsosetLanguageChangeEnabled().

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

Loads a form from the givendevice and creates a new widget with the givenparentWidget to hold its contents.

See alsocreateWidget().

QStringList QUiLoader::pluginPaths() const

Returns a list naming the paths in which the loader will search when locating custom widget plugins.

See alsoaddPluginPath() andclearPluginPaths().

void QUiLoader::setLanguageChangeEnabled(bool enabled)

Ifenabled is true, user interfaces loaded by this loader will automatically retranslate themselves upon receiving a language change event. Otherwise, the user interfaces will not be retranslated.

This function was introduced in Qt 4.5.

See alsoisLanguageChangeEnabled().

void QUiLoader::setWorkingDirectory(constQDir & dir)

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

See alsoworkingDirectory().

QDir QUiLoader::workingDirectory() const

Returns the working directory of the loader.

See alsosetWorkingDirectory().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp