diff options
author | Venugopal Shivashankar <Venugopal.Shivashankar@qt.io> | 2020-05-28 14:27:16 +0200 |
---|---|---|
committer | Cristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2020-05-28 16:52:30 +0200 |
commit | 98cae0c9f2fc9f76d12672462bd4fe984074f8eb (patch) | |
tree | 98392d9bc2d08467fe86f3f7f346d276682e397b | |
parent | 7406fc4b6967cb32175752a2ae7934bd8b1f8200 (diff) |
Doc: Document QtUiTools.loadUiType function
Removing the old inject-documentation approach
from the typesystem, since the function lives in the module
but does not belong to any class.
Also some changes to the text were done, since there was
a wrong statement regarding the PATH of uic.
Change-Id: I7c8bf088f58ff9b6731ba66283ee384f6526c64b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml | 25 | ||||
-rw-r--r-- | sources/pyside2/doc/extras/QtUiTools.loadUiType.rst | 36 |
2 files changed, 36 insertions, 25 deletions
diff --git a/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml index 2ca12e788..85092a5c2 100644 --- a/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml +++ b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml @@ -146,31 +146,6 @@ 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> diff --git a/sources/pyside2/doc/extras/QtUiTools.loadUiType.rst b/sources/pyside2/doc/extras/QtUiTools.loadUiType.rst new file mode 100644 index 000000000..9ca330dea --- /dev/null +++ b/sources/pyside2/doc/extras/QtUiTools.loadUiType.rst @@ -0,0 +1,36 @@ +.. currentmodule:: PySide2.QtUiTools +.. _loadUiType: + +loadUiType +*********** + +.. py:function:: loadUiType(uifile: str) -> tuple(object, object) + + :param str uifile: The name of the `.ui` file + :return: tuple(object, object) + + This function generates and loads a `.ui` file at runtime, and it returns + a `tuple` containing the reference to the Python class, and the base class. + + We recommend not to use this approach as 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. + The `pyside2-uic` wrapper uses a shipped `uic` that is located in the + `site-packages/PySide2/uic`, so PATH needs to be updated to use that if there + is no `uic` in the system. + + A simple use case is:: + + from PySide2.QtUiTools import loadUiType + + generated_class, base_class = loadUiType("themewidget.ui") + # the values will be: + # (<class '__main__.Ui_ThemeWidgetForm'>, <class 'PySide2.QtWidgets.QWidget'>) + + widget = base_class() + form = generated_class() + form.setupUi(widget) + # form.a_widget_member.a_method_of_member() + widget.show() |