forked from qt-creator/qt-creator
Doc: Describe creating a PySide6 project with the wizard
Task-number: QTCREATORBUG-26278 Change-Id: I643a10cff0a30f0de31851dc5d2077c11248f62e Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 11 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 8.2 KiB |
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the Qt Creator documentation.
|
** This file is part of the Qt Creator documentation.
|
||||||
@@ -29,8 +29,8 @@
|
|||||||
\section2 Creating Widget-Based Qt for Python Applications
|
\section2 Creating Widget-Based Qt for Python Applications
|
||||||
|
|
||||||
\l {https://doc.qt.io/qtforpython/index.html}{Qt for Python} enables you
|
\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
|
to use Qt 6 API in Python applications. You can use the PySide6 modules
|
||||||
gain access to individual Qt modules, such as \l {Qt Core}, \l {Qt GUI},
|
to gain access to individual Qt modules, such as \l {Qt Core}, \l {Qt GUI},
|
||||||
and \l {Qt Widgets}.
|
and \l {Qt Widgets}.
|
||||||
|
|
||||||
The Qt for Python Application wizards generate a \c {.pyproject} file that
|
The Qt for Python Application wizards generate a \c {.pyproject} file that
|
||||||
@@ -46,7 +46,8 @@
|
|||||||
|
|
||||||
The \uicontrol {Qt for Python - Window (UI file)} wizard enables you to
|
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
|
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.
|
the PySide version, class name, base class, and and source file for the
|
||||||
|
class.
|
||||||
|
|
||||||
\image qtcreator-python-wizard-app-window.png "Qt for Python wizard for creating a widget-based UI"
|
\image qtcreator-python-wizard-app-window.png "Qt for Python wizard for creating a widget-based UI"
|
||||||
|
|
||||||
@@ -55,21 +56,22 @@
|
|||||||
Widgets module, and Qt UI tools:
|
Widgets module, and Qt UI tools:
|
||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
from PySide2.QtWidgets import QApplication, QWidget
|
from PySide6.QtWidgets import QApplication, QWidget
|
||||||
from PySide2.QtCore import QFile
|
from PySide6.QtCore import QFile
|
||||||
from PySide2.QtUiTools import QUiLoader
|
from PySide6.QtUiTools import QUiLoader
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
The wizard also adds a main class with the specified name that
|
The wizard also adds a main class with the specified name that
|
||||||
inherits from the specified base class:
|
inherits from the specified base class:
|
||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
class MyWidget(QWidget):
|
class Widget(QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(MyWidget, self).__init__()
|
super(Widget, self).__init__()
|
||||||
self.load_ui()
|
self.load_ui()
|
||||||
...
|
...
|
||||||
\endcode
|
\endcode
|
||||||
@@ -80,7 +82,7 @@
|
|||||||
\badcode
|
\badcode
|
||||||
def load_ui(self):
|
def load_ui(self):
|
||||||
loader = QUiLoader()
|
loader = QUiLoader()
|
||||||
path = os.path.join(os.path.dirname(__file__), "form.ui")
|
path = os.fspath(Path(__file__).resolve().parent / "form.ui")
|
||||||
ui_file = QFile(path)
|
ui_file = QFile(path)
|
||||||
ui_file.open(QFile.ReadOnly)
|
ui_file.open(QFile.ReadOnly)
|
||||||
loader.load(ui_file, self)
|
loader.load(ui_file, self)
|
||||||
@@ -100,8 +102,8 @@
|
|||||||
Next, the wizard instantiates the \c MainWindow class and shows it:
|
Next, the wizard instantiates the \c MainWindow class and shows it:
|
||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
window = MyWidget()
|
widget = Widget()
|
||||||
window.show()
|
widget.show()
|
||||||
...
|
...
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
@@ -153,12 +155,12 @@
|
|||||||
to QGuiApplication and QQmlApplicationEngine:
|
to QGuiApplication and QQmlApplicationEngine:
|
||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
from PySide2.QtGui import QGuiApplication
|
from PySide6.QtGui import QGuiApplication
|
||||||
from PySide2.QtQml import QQmlApplicationEngine
|
from PySide6.QtQml import QQmlApplicationEngine
|
||||||
|
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
The wizard also adds a main function, where it creates a QGuiApplication
|
The wizard also adds a main function, where it creates a QGuiApplication
|
||||||
@@ -175,7 +177,7 @@
|
|||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
engine = QQmlApplicationEngine()
|
engine = QQmlApplicationEngine()
|
||||||
engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
|
engine.load(os.fspath(Path(__file__).resolve().parent / "main.qml"))
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
Finally, the wizard adds code that checks whether the file was successfully
|
Finally, the wizard adds code that checks whether the file was successfully
|
||||||
@@ -190,7 +192,7 @@
|
|||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
Open the .qml file in the \uicontrol Edit mode to design a Qt Quick UI, or
|
Open the .qml file in the \uicontrol Edit mode to design a Qt Quick UI, or
|
||||||
use \QDS.
|
use \l{Qt Design Studio Manual}{\QDS}.
|
||||||
|
|
||||||
//! [python qml project wizards]
|
//! [python qml project wizards]
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user