forked from qt-creator/qt-creator
Doc: Rearrange files in the doc folder
Source and configuration files for each manual are now located in a separate subdirectory, with common configuration files in doc/config. doc |_config |_qtcreator |_qtcreatordev |_qtdesignstudio Edit the config files accordingly. Change-Id: Idc747a7c16e84f3e06add91234dc5fc908e64cc5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
187
doc/qtcreator/src/python/creator-python-project.qdocinc
Normal file
187
doc/qtcreator/src/python/creator-python-project.qdocinc
Normal file
@@ -0,0 +1,187 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt Creator documentation.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Free Documentation License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Free
|
||||
** Documentation License version 1.3 as published by the Free Software
|
||||
** Foundation and appearing in the file included in the packaging of
|
||||
** this file. Please review the following information to ensure
|
||||
** the GNU Free Documentation License version 1.3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
//! [python project wizards]
|
||||
|
||||
\section2 Creating Widget-Based Qt for Python Applications
|
||||
|
||||
\l {https://doc.qt.io/qtforpython/index.html}{Qt for Python} enables you
|
||||
to use Qt 5 API in Python applications. You can use the PySide2 module to
|
||||
gain access to individual Qt modules, such as \l {Qt Core}, \l {Qt GUI},
|
||||
and \l {Qt Widgets}.
|
||||
|
||||
The Qt for Python Application wizards generate a \c {.pyproject} file that
|
||||
lists the files in the Python project and a \c {.py} file that contains
|
||||
some boilerplate code. In addition, the widget based UI wizard creates a
|
||||
\c {.ui} file that contains a \QD form, and the Qt Quick Application wizard
|
||||
creates a \c {.qml} file that contains Qt Quick controls.
|
||||
|
||||
The \c{.pyproject} files are JSON-based configuration files that replace
|
||||
the previously used \c {.pyqtc} configuration files. You can still open and
|
||||
use \c {.pyqtc} files, but we recommend that you choose \c{.pyproject} files
|
||||
for new projects.
|
||||
|
||||
The \uicontrol {Qt for Python - Window (UI file)} wizard enables you to
|
||||
create a Python project that contains the source file for a class. Specify
|
||||
the class name, base class, and and source file for the class.
|
||||
|
||||
\image qtcreator-python-wizard-app-window.png
|
||||
|
||||
The wizard adds the imports to the source file to provide
|
||||
access to the QApplication, the base class you selected in the Qt
|
||||
Widgets module, and Qt UI tools:
|
||||
|
||||
\badcode
|
||||
import sys
|
||||
import os
|
||||
|
||||
from PySide2.QtWidgets import QApplication, QWidget
|
||||
from PySide2.QtCore import QFile
|
||||
from PySide2.QtUiTools import QUiLoader
|
||||
\endcode
|
||||
|
||||
The wizard also adds a main class with the specified name that
|
||||
inherits from the specified base class:
|
||||
|
||||
\badcode
|
||||
class MyWidget(QWidget):
|
||||
def __init__(self):
|
||||
super(MyWidget, self).__init__()
|
||||
self.load_ui()
|
||||
...
|
||||
\endcode
|
||||
|
||||
The following lines in the main class load the generated Python class from
|
||||
the UI file:
|
||||
|
||||
\badcode
|
||||
def load_ui(self):
|
||||
loader = QUiLoader()
|
||||
path = os.path.join(os.path.dirname(__file__), "form.ui")
|
||||
ui_file = QFile(path)
|
||||
ui_file.open(QFile.ReadOnly)
|
||||
loader.load(ui_file, self)
|
||||
ui_file.close()
|
||||
\endcode
|
||||
|
||||
Next, the wizard adds a main function, where it creates a
|
||||
QApplication instance. As Qt can receive arguments from the command line,
|
||||
you can pass any arguments to the QApplication object. Usually, you do not
|
||||
need to pass any arguments, and you can use the following approach:
|
||||
|
||||
\badcode
|
||||
if __name__ == "__main__":
|
||||
app = QApplication([])
|
||||
\endcode
|
||||
|
||||
Next, the wizard instantiates the \c MainWindow class and shows it:
|
||||
|
||||
\badcode
|
||||
window = MyWidget()
|
||||
window.show()
|
||||
...
|
||||
\endcode
|
||||
|
||||
Finally, the wizard calls the \c app.exec_() method to enter the Qt
|
||||
main loop and start executing the Qt code:
|
||||
|
||||
\badcode
|
||||
sys.exit(app.exec_())
|
||||
\endcode
|
||||
|
||||
Open the .ui file in the Design mode to create a widget-based UI in \QD.
|
||||
|
||||
The \uicontrol Window wizard adds similar code to the source file, without
|
||||
the UI bits.
|
||||
|
||||
The \uicontrol Empty wizard adds similar code to the source file, but it
|
||||
does not add any classes, so you need to add and instantiate them yourself.
|
||||
|
||||
For more information about the
|
||||
\uicontrol {Qt for Python - Qt Quick Application - Empty} wizard, see
|
||||
\l {Creating Qt Quick Based Python Applications}.
|
||||
|
||||
For examples of creating Qt for Python applications, see
|
||||
\l {https://doc.qt.io/qtforpython/tutorials/index.html}
|
||||
{Qt for Python Examples and Tutorials}.
|
||||
|
||||
//! [python project wizards]
|
||||
|
||||
|
||||
//! [python qml project wizards]
|
||||
|
||||
\section1 Creating Qt Quick Based Python Applications
|
||||
|
||||
The \uicontrol {Qt for Python - Qt Quick Application - Empty} wizard enables
|
||||
you to create a Python project that contains a main QML file. Specify the
|
||||
minimum PySide version to run the application.
|
||||
|
||||
\image qtcreator-python-wizard-qml.png
|
||||
|
||||
The wizard adds the following imports to the source file to provide access
|
||||
to QGuiApplication and QQmlApplicationEngine:
|
||||
|
||||
\badcode
|
||||
import sys
|
||||
import os
|
||||
|
||||
from PySide2.QtGui import QGuiApplication
|
||||
from PySide2.QtQml import QQmlApplicationEngine
|
||||
|
||||
\endcode
|
||||
|
||||
The wizard also adds a main function, where it creates a QGuiApplication
|
||||
instance and passes system arguments to the QGuiApplication object:
|
||||
|
||||
\badcode
|
||||
if __name__ == "__main__":
|
||||
app = QGuiApplication(sys.argv)
|
||||
...
|
||||
\endcode
|
||||
|
||||
The following lines in the main class create a QQmlApplicationEngine
|
||||
instance and load the generated QML file to the engine object:
|
||||
|
||||
\badcode
|
||||
engine = QQmlApplicationEngine()
|
||||
engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
|
||||
\endcode
|
||||
|
||||
Finally, the wizard adds code that checks whether the file was successfully
|
||||
loaded. If loading the file fails, the application exits with an error code.
|
||||
If loading succeeds, the wizard calls the \c app.exec_() method to enter the
|
||||
Qt main loop and start executing the Qt code:
|
||||
|
||||
\badcode
|
||||
if not engine.rootObjects():
|
||||
sys.exit(-1)
|
||||
sys.exit(app.exec_())
|
||||
\endcode
|
||||
|
||||
Open the .qml file in the Design mode to design a Qt Quick UI in \QMLD.
|
||||
|
||||
//! [python qml project wizards]
|
||||
*/
|
||||
73
doc/qtcreator/src/python/creator-python-run.qdocinc
Normal file
73
doc/qtcreator/src/python/creator-python-run.qdocinc
Normal file
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt Creator documentation.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Free Documentation License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Free
|
||||
** Documentation License version 1.3 as published by the Free Software
|
||||
** Foundation and appearing in the file included in the packaging of
|
||||
** this file. Please review the following information to ensure
|
||||
** the GNU Free Documentation License version 1.3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
//! [running python]
|
||||
\section1 Running Python Projects
|
||||
|
||||
You can execute Qt for Python applications directly from \QC. If you
|
||||
used the \l{Using Project Wizards}{new project wizard}
|
||||
to create the application project, the \c main.py file is automatically
|
||||
executed when you select the \uicontrol Run button.
|
||||
|
||||
You can specify another file to execute in the
|
||||
\l{Specifying Run Settings for Python Projects}{run settings}
|
||||
of the project.
|
||||
|
||||
//! [running python]
|
||||
|
||||
|
||||
//! [run settings python]
|
||||
|
||||
\section1 Specifying Run Settings for Python Projects
|
||||
|
||||
You can specify settings for running Qt for Python applications:
|
||||
|
||||
\image qtcreator-python-run-settings.png
|
||||
|
||||
\list
|
||||
\li In the \uicontrol Interpreter field, specify the path to the
|
||||
Python executable.
|
||||
\li In the \uicontrol Script field, you can see the path to the
|
||||
main file of the project that will be run.
|
||||
\li In the \uicontrol {Command line arguments} field, specify
|
||||
command line arguments to be passed to the executable.
|
||||
\endlist
|
||||
|
||||
If you want to run some other Python file than \c main.py, create a custom
|
||||
executable run configuration:
|
||||
|
||||
\image qtcreator-python-run-settings-custom-executable.png
|
||||
|
||||
\list 1
|
||||
\li Select \uicontrol Add > \uicontrol {Custom Executable}.
|
||||
\li In the \uicontrol Executable field, specify the path to the
|
||||
Python executable.
|
||||
\li In the \uicontrol {Command line arguments} field, select
|
||||
the Python file to run.
|
||||
\endlist
|
||||
|
||||
//! [run settings python]
|
||||
*/
|
||||
Reference in New Issue
Block a user