
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
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 |
| QUiLoader(QObject * parent = 0) | |
| virtual | ~QUiLoader() |
| void | addPluginPath(const QString & path) |
| QStringList | availableLayouts() const |
| QStringList | availableWidgets() const |
| void | clearPluginPaths() |
| 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()) |
| bool | isLanguageChangeEnabled() const |
| QWidget * | load(QIODevice * device, QWidget * parentWidget = 0) |
| QStringList | pluginPaths() const |
| void | setLanguageChangeEnabled(bool enabled) |
| void | setWorkingDirectory(const QDir & dir) |
| QDir | workingDirectory() const |
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.
Creates a form loader with the givenparent.
[virtual]QUiLoader::~QUiLoader()Destroys the loader.
Adds the givenpath to the list of paths in which the loader will search when locating plugins.
See alsopluginPaths() andclearPluginPaths().
Returns a list naming all available layouts that can be built using thecreateLayout() function
This function was introduced in Qt 4.5.
See alsocreateLayout().
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().
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().
Returns true if dynamic retranslation on language change is enabled; returns false otherwise.
This function was introduced in Qt 4.5.
See alsosetLanguageChangeEnabled().
Loads a form from the givendevice and creates a new widget with the givenparentWidget to hold its contents.
See alsocreateWidget().
Returns a list naming the paths in which the loader will search when locating custom widget plugins.
See alsoaddPluginPath() andclearPluginPaths().
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().
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().
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.