forked from qt-creator/qt-creator
Doc: Update the docs about Python development
Task-number: QTCREATORBUG-30209 Change-Id: I3023fb6b9005092ecd76f62774942f366e1bd7d9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -19,9 +19,8 @@
|
||||
\list
|
||||
\li \l{Set up PySide6}
|
||||
\li \l{Create Qt for Python applications}
|
||||
\li \l{Select the Python interpreter}
|
||||
\li \l{Create a virtual environment}
|
||||
\li \l{Create kits for Python interpreters}
|
||||
\li \l{Select the Python version}
|
||||
\li \l{Create kits for Python}
|
||||
\li \l{Use Python interactive shell}
|
||||
\li \l{Configure Python language servers}
|
||||
\li \l{Run Python applications}
|
||||
@@ -48,9 +47,10 @@
|
||||
|
||||
\section1 Create Qt for Python applications
|
||||
|
||||
You can use wizards to create Qt for Python application projects. The wizards
|
||||
Use wizards to create Qt for Python application projects. The wizards
|
||||
generate a project file, \c {.pyproject}, that lists the files in the Python
|
||||
project. They also generate a \c {.py} file that has some boilerplate code.
|
||||
project. They also generate a \c {.py} file that has some boilerplate code
|
||||
and \c {reguirements.txt} that stores the PySide version of the generated code.
|
||||
In addition, the widget-based UI wizard creates a \c {.ui} file that has a
|
||||
\QD form, and the Qt Quick Application wizard creates a \c {.qml} file that
|
||||
imports Qt Quick controls.
|
||||
@@ -72,50 +72,31 @@
|
||||
use \c {.pyqtc} files, but we recommend that you choose \c{.pyproject} files
|
||||
for new projects.
|
||||
|
||||
\section1 Select the Python interpreter
|
||||
\section1 Select the Python version
|
||||
|
||||
You select the initial Python interpreter when you use the Qt for Python
|
||||
Application wizard templates to create Python projects.
|
||||
The \l{kits-tab}{kits} you select for the project in \uicontrol Projects >
|
||||
\uicontrol {Build & Run} set the Python version to use.
|
||||
|
||||
\image qtcreator-new-qt-for-python-app-widgets-project-details.webp {Define Project Details dialog}
|
||||
The \l {Edit Mode}{Edit mode} toolbar shows the current Python version.
|
||||
|
||||
You can see the current Python interpreter on the \uicontrol Edit mode
|
||||
toolbar.
|
||||
\image qtcreator-python-interpreter-edit-mode.webp {Python version on the Edit mode toolbar}
|
||||
|
||||
\image qtcreator-python-interpreter-edit-mode.webp {Python interpreter on the Edit mode toolbar}
|
||||
To use another Python version, activate another kit for the project.
|
||||
|
||||
You can change the interpreter to use for a particular project in
|
||||
\uicontrol Projects > \uicontrol Run > \uicontrol Interpreter.
|
||||
\section1 Create kits for Python
|
||||
|
||||
\image qtcreator-python-run-settings.png {Python run settings}
|
||||
|
||||
To see the available interpreters and choose another interpreter, select the
|
||||
current interpreter, and then select \uicontrol {Manage Python Interpreters}.
|
||||
Or, select \preferences > \uicontrol Python > \uicontrol Interpreters.
|
||||
\QC automatically adds all Python versions it can find to the list of
|
||||
Python versions in \preferences > \uicontrol Python > \uicontrol Interpreters.
|
||||
It generates kits for the global Python versions that are not inside a
|
||||
virtual environment.
|
||||
|
||||
\image qtcreator-python-interpreters.webp {Python Interpreters in Preferences}
|
||||
|
||||
You can add and remove interpreters and clean up references to interpreters
|
||||
that you uninstalled, but that still appear in the list.
|
||||
You can add and remove Python versions and clean up references to Python
|
||||
versions that you uninstalled, but that still appear in the list.
|
||||
|
||||
To use the selected Python interpreter by default, select
|
||||
\uicontrol {Make Default}.
|
||||
|
||||
\section1 Create a virtual environment
|
||||
|
||||
To use a clean \l{https://docs.python.org/3/library/venv.html}{Python}
|
||||
virtual environment (\c venv) that is independent of your global Python
|
||||
installation for a Qt for Python project, select the
|
||||
\uicontrol {Create new virtual environment} check box in the project wizard.
|
||||
Set the directory where to create the environment in
|
||||
\uicontrol {Path to virtual environment}.
|
||||
|
||||
\section1 Create kits for Python interpreters
|
||||
|
||||
\QC automatically adds all Python interpreters it can find to the list of
|
||||
interpreters in \preferences > \uicontrol Python > \uicontrol Interpreters.
|
||||
It generates \l{kits-tab}{kits} for the global Python interpreters that are
|
||||
not inside a virtual environment.
|
||||
To use the selected Python version when opening \c {.py} files that don't
|
||||
belong to a project, select \uicontrol {Make Default}.
|
||||
|
||||
To use a virtual environment as a kit, select it in \uicontrol Interpreters,
|
||||
and then select \uicontrol {Generate Kit}.
|
||||
@@ -133,5 +114,6 @@
|
||||
the file, select \uicontrol {REPL Import *}.
|
||||
|
||||
\sa {Creating a Qt for Python Application with Qt Widgets},
|
||||
{Creating a Qt for Python Application with Qt Quick}
|
||||
{Creating a Qt for Python Application with Qt Quick},
|
||||
{Activate kits for a project}
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
you select for a kit in \uicontrol Projects > \uicontrol {Build & Run} >
|
||||
\uicontrol Run > \uicontrol {Run Settings}.
|
||||
|
||||
\image qtcreator-python-run-settings.png {Python run settings}
|
||||
\image qtcreator-python-run-settings.webp {Python run settings}
|
||||
|
||||
The following table summarizes the settings for running Qt for Python
|
||||
applications.
|
||||
@@ -45,7 +45,7 @@
|
||||
\li Setting
|
||||
\li Value
|
||||
\row
|
||||
\li \uicontrol Interpreter
|
||||
\li \uicontrol Python
|
||||
\li Path to the Python executable.
|
||||
\row
|
||||
\li \uicontrol {Buffered output}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
||||
|
||||
/*!
|
||||
@@ -28,11 +28,10 @@
|
||||
class:
|
||||
|
||||
\list 1
|
||||
\li Select \uicontrol File > \uicontrol {New Project} >
|
||||
\uicontrol {Application (Qt for Python)} > \uicontrol {Empty Window}
|
||||
> \uicontrol Choose.
|
||||
|
||||
The \uicontrol {Project Location} dialog opens.
|
||||
\li Go to \uicontrol File > \uicontrol {New Project}.
|
||||
\li Select \uicontrol {Application (Qt for Python)} >
|
||||
\uicontrol {Empty Window} > \uicontrol Choose to open the
|
||||
\uicontrol {Project Location} dialog.
|
||||
\image qtcreator-new-qt-for-python-app-widgets-project-location.webp {Project Location dialog}
|
||||
\li In \uicontrol {Name}, enter the project name. For example,
|
||||
\e {hello_world}.
|
||||
@@ -49,16 +48,14 @@
|
||||
\li In \uicontrol {Project file}, enter a name for the project file.
|
||||
\li Select \uicontrol{Next} or \uicontrol Continue to open the
|
||||
\uicontrol {Define Project Details} dialog.
|
||||
\image qtcreator-new-qt-for-python-app-widgets-project-details.webp {Define Project Details dialog}
|
||||
\image qtcreator-new-qt-for-python-app-project-details.webp {Define Project Details dialog}
|
||||
\li In \uicontrol {PySide version}, select the PySide version of the
|
||||
generated code.
|
||||
\li In \uicontrol {Interpreter}, select the Python interpreter to use for
|
||||
the project.
|
||||
\li Select the \uicontrol {Create new virtual environment} check box to
|
||||
use a clean \l{https://docs.python.org/3/library/venv.html}{Python}
|
||||
environment that is independent of your global Python installation.
|
||||
\li In \uicontrol {Path to virtual environment}, specify the directory
|
||||
where to create the environment.
|
||||
\li Select \uicontrol{Next} or \uicontrol Continue to open the
|
||||
\uicontrol {Kit Selection} dialog.
|
||||
\image qtcreator-new-project-qt-for-python-kit-selection.webp {Selecting a kit for a Python project}
|
||||
\li Select Qt for Python kits for building, deploying, and running the
|
||||
project.
|
||||
\li Select \uicontrol{Next} or \uicontrol Continue.
|
||||
\li Review the project settings, and select \uicontrol {Finish} (on
|
||||
Windows and Linux) or \uicontrol Done (on \macos) to create the
|
||||
@@ -71,6 +68,8 @@
|
||||
\li \c {hellow_world.pyproject}, which lists the files in the Python
|
||||
project.
|
||||
\li \c {mywidget.py}, which has some boilerplate code for a class.
|
||||
\li \c {reguirements.txt}, which stores the PySide version of the
|
||||
generated code.
|
||||
\endlist
|
||||
|
||||
\section1 Adding Qt Widgets Imports
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
||||
|
||||
/*!
|
||||
@@ -18,16 +18,19 @@
|
||||
|
||||
\image qtcreator-new-qt-for-python-app-qt-quick-empty-project-ready.webp {A small Qt Quick application}
|
||||
|
||||
For more examples of creating Qt for Python applications, see
|
||||
\l {https://doc.qt.io/qtforpython/tutorials/index.html}
|
||||
{Qt for Python Examples and Tutorials}.
|
||||
|
||||
\section1 Creating an Empty Project
|
||||
|
||||
To create a Qt for Python application that has a main QML file:
|
||||
|
||||
\list 1
|
||||
\li Select \uicontrol File > \uicontrol {New Project} >
|
||||
\uicontrol {Application (Qt for Python)} >
|
||||
\uicontrol {Qt Quick Application - Empty} > \uicontrol Choose.
|
||||
|
||||
The \uicontrol {Project Location} dialog opens.
|
||||
\li Go to \uicontrol File > \uicontrol {New Project}.
|
||||
\li Select \uicontrol {Application (Qt for Python)} >
|
||||
\uicontrol {Qt Quick Application - Empty} > \uicontrol Choose to
|
||||
open the \uicontrol {Project Location} dialog.
|
||||
\image qtcreator-new-qt-for-python-app-qt-quick-empty-project-location.webp {Project Location dialog}
|
||||
\li In \uicontrol {Name}, enter the project name. For example,
|
||||
\e {hello_world_quick}.
|
||||
@@ -35,17 +38,14 @@
|
||||
For example, \c {C:\Qt\examples}.
|
||||
\li Select \uicontrol{Next} (on Windows and Linux) or \uicontrol Continue
|
||||
(on \macos) to open the \uicontrol {Define Project Details} dialog.
|
||||
\image qtcreator-new-qt-for-python-app-qt-quick-empty-project-details.webp {Define Project Details dialog}
|
||||
\image qtcreator-new-qt-for-python-app-project-details.webp {Define Project Details dialog}
|
||||
\li In \uicontrol {PySide version}, select the PySide version of
|
||||
the generated code.
|
||||
\li In \uicontrol {Interpreter}, select the Python interpreter to use for
|
||||
the project.
|
||||
\li Select the \uicontrol {Create new virtual environment} check box to
|
||||
use a clean \l{https://docs.python.org/3/library/venv.html}{Python}
|
||||
environment that is independent of your global Python installation.
|
||||
\li In \uicontrol {Path to virtual environment}, specify the directory
|
||||
where to create the environment.
|
||||
\li Select \uicontrol{Next} or \uicontrol Continue.
|
||||
\li Select \uicontrol{Next} or \uicontrol Continue to open the
|
||||
\uicontrol {Kit Selection} dialog.
|
||||
\image qtcreator-new-project-qt-for-python-kit-selection.webp {Selecting a kit for a Python project}
|
||||
\li Select Qt for Python kits for building, deploying, and running the
|
||||
project.
|
||||
\li Review the project settings, and select \uicontrol {Finish} (on
|
||||
Windows and Linux) or \uicontrol Done (on \macos) to create the
|
||||
project.
|
||||
@@ -58,6 +58,8 @@
|
||||
project.
|
||||
\li \c {main.py}, which has some boilerplate code.
|
||||
\li \c {main.qml}, which imports Qt Quick controls.
|
||||
\li \c {reguirements.txt}, which stores the PySide version of the
|
||||
generated code.
|
||||
\endlist
|
||||
|
||||
\section1 Adding Qt Quick Imports
|
||||
|
||||
Reference in New Issue
Block a user