diff --git a/doc/qtcreator/src/projects/creator-only/creator-projects-creating.qdoc b/doc/qtcreator/src/projects/creator-only/creator-projects-creating.qdoc index 8d0a1cf8ef8..6acd3667a1f 100644 --- a/doc/qtcreator/src/projects/creator-only/creator-projects-creating.qdoc +++ b/doc/qtcreator/src/projects/creator-only/creator-projects-creating.qdoc @@ -130,6 +130,12 @@ \li Empty Window \li Creates a Qt for Python application that contains an empty window. + \row + \li Window UI + \li Creates a Qt for Python application that contains an empty + window with a widget-based UI. Preferred approach that requires + you to generate a Python file from the .ui file, to import + it directly into your application. \row \li Window UI - Dynamic load \li Creates a Qt for Python application that contains an empty diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget_gen.py b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget_gen.py new file mode 100644 index 00000000000..bd7d4fa807d --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget_gen.py @@ -0,0 +1,39 @@ +# This Python file uses the following encoding: utf-8 +import sys + +@if '%{BaseCB}' === 'QWidget' +from %{PySideVersion}.QtWidgets import QApplication, QWidget +@endif +@if '%{BaseCB}' === 'QMainWindow' +from %{PySideVersion}.QtWidgets import QApplication, QMainWindow +@endif +@if '%{BaseCB}' === 'QDialog' +from %{PySideVersion}.QtWidgets import QApplication, QDialog +@endif + +# Important: +# You need to run the following command to generate the ui_form.py file +# pyside6-uic form.ui -o ui_form.py, or +# pyside2-uic form.ui -o ui_form.py +from ui_form import Ui_%{Class} + +@if '%{BaseCB}' +class %{Class}(%{BaseCB}): +@else +class %{Class}: +@endif + def __init__(self, parent=None): + super().__init__(parent) + self.ui = Ui_%{Class}() + self.ui.setupUi(self) + + +if __name__ == "__main__": + app = QApplication(sys.argv) + widget = %{Class}() + widget.show() +@if '%{PySideVersion}' === 'PySide6' + sys.exit(app.exec()) +@else + sys.exit(app.exec_()) +@endif diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/main.pyproject b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/main.pyproject new file mode 100644 index 00000000000..64c2987a8fb --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/main.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["%{SrcFileName}", "form.ui"] +} diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/wizard.json b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/wizard.json new file mode 100644 index 00000000000..1a2bcec74b4 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/wizard.json @@ -0,0 +1,110 @@ +{ + "version": 1, + "supportedProjectTypes": [ "PythonProject" ], + "id": "F.QtForPythonApplicationWindowWidgetGen", + "category": "F.ApplicationPySide", + "trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (ui file) - Requires .ui to Python conversion", + "trDisplayName": "Window UI", + "trDisplayCategory": "Application (Qt for Python)", + "icon": "../icons/icon.png", + "iconKind": "Themed", + "enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}", + + "options": + [ + { "key": "SrcFileName", "value": "%{MainFileName}" }, + { "key": "PyProjectFile", "value": "%{ProjectFileName}" } + ], + + "pages": + [ + { + "trDisplayName": "Project Location", + "trShortTitle": "Location", + "typeId": "Project", + "name": "ProjectPath" + }, + { + "trDisplayName": "Define Class", + "trShortTitle": "Details", + "typeId": "Fields", + "data" : + [ + { + "name": "PySideVersion", + "trDisplayName": "PySide version:", + "type": "ComboBox", + "data": { "items": [ "PySide2", "PySide6" ] } + }, + { + "name": "Class", + "trDisplayName": "Class name:", + "mandatory": true, + "type": "LineEdit", + "data": + { + "validator": "(?:(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*|)", + "trText": "%{JS: value('BaseCB') ? value('BaseCB').slice(1) : 'MyClass'}" + } + + }, + { + "name": "BaseCB", + "trDisplayName": "Base class:", + "type": "ComboBox", + "data": + { + "items": [ "QWidget", "QDialog", "QMainWindow" ] + } + }, + { + "name": "MainFileName", + "type": "LineEdit", + "trDisplayName": "Source file:", + "mandatory": true, + "data": { "trText": "%{JS: Cpp.classToFileName(value('Class'), Util.preferredSuffix('text/x-python'))}" } + }, + { + "name": "ProjectFileName", + "type": "LineEdit", + "trDisplayName": "Project file:", + "mandatory": true, + "data": { "trText": "%{JS: Util.fileName('%{ProjectName}', 'pyproject')}" } + } + ] + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "main.pyproject", + "target": "%{PyProjectFile}", + "openAsProject": true + }, + { + "source": "../main_widget_gen.py", + "target": "%{SrcFileName}", + "openInEditor": true + }, + { + "source": "../main_widget.ui", + "target": "form.ui" + }, + { + "source": "../../git.ignore", + "target": ".gitignore", + "condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}" + } + ] + } + ] +}