diff options
author | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2020-03-26 18:34:38 +0100 |
---|---|---|
committer | Cristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2020-05-25 14:36:52 +0200 |
commit | 6717d3540fac74c91d9381958a08e60f6532d402 (patch) | |
tree | 7a41295b3a6c79b82de5b9846573b3ee8e61c6cb /sources/pyside2/PySide2/QtUiTools | |
parent | 15e470d1af2274579bd0709fc56e6788f44874d2 (diff) |
Add QtUiTools.loadUiType
This function will allow users to convert and load .ui files
at runtime.
A test case was added.
Change-Id: I64a220a07955e560f61f823d0ee2c3c9ff2209c1
Fixes: PYSIDE-1223
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside2/PySide2/QtUiTools')
-rw-r--r-- | sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml index 7b27e8783..2ca12e788 100644 --- a/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml +++ b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml @@ -139,4 +139,40 @@ </add-function> </object-type> + <!-- + After the removal of the 'pysideuic' Python module, many users were unable to generate and + load UI classes dynamically. + This function was created to provide an equivalent solution to the 'loadUiType' function from + Riverbank's PyQt. + --> + <add-function signature="loadUiType(const QString& @uifile@)" return-type="PyObject*"> + <inject-documentation format="target" mode="append"> + This function will allow users to generate and load a `.ui` file at runtime, and it returns + a `tuple` containing the reference to the Python class, and the base class. + + We don't recommend this approach since the workflow should be to generate a Python file + from the `.ui` file, and then import and load it to use it, but we do understand that + there are some corner cases when such functionality is required. + + The internal process relies on `uic` being in the PATH, which is the same requirement for + the new `pyside2-uic` to work (which is just a wrapper around `uic -g python`) + + A Simple use can be: + + .. code-block:: python + + from PySide2.QtUiTools import loadUiType + + generated_class, base_class = loadUiType("themewidget.ui") + # the values will be: + # (<class '__main__.Ui_ThemeWidgetForm'>, <class 'PySide2.QtWidgets.QWidget'>) + + + In that case, `generated_class` will be a reference to the Python class, + and `base_class` will be a reference to the base class. + </inject-documentation> + <inject-code file="../glue/qtuitools.cpp" snippet="loaduitype"/> + </add-function> + + </typesystem> |