aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/tutorials
diff options
context:
space:
mode:
authorCristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2023-04-04 17:19:23 +0200
committerCristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2023-04-05 09:26:43 +0200
commit900c050c66119454585ec83cf31149f6d64dd3ea (patch)
treec9db45471d33aaf9ca6ad7de191d73eed2cbec24 /sources/pyside6/doc/tutorials
parentd35b650fe4369952a44c3891fedb6d8ee1417df5 (diff)
doc: fix issues with pyside rst files
Fixing extra indentation, syntax issues, and formatting. Adapting too some snippet line highlights, and many other details. Pick-to: 6.5 Change-Id: Ife4eb5cec03577b2902d409b4007ae6d12141747 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/doc/tutorials')
-rw-r--r--sources/pyside6/doc/tutorials/basictutorial/dialog.rst40
-rw-r--r--sources/pyside6/doc/tutorials/basictutorial/qrcfiles.rst24
-rw-r--r--sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst30
-rw-r--r--sources/pyside6/doc/tutorials/basictutorial/translations.rst140
-rw-r--r--sources/pyside6/doc/tutorials/basictutorial/uifiles.rst26
-rw-r--r--sources/pyside6/doc/tutorials/basictutorial/widgetstyling.rst36
-rw-r--r--sources/pyside6/doc/tutorials/debugging/qtcreator/qtcreator.rst26
-rw-r--r--sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst42
-rw-r--r--sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst14
-rw-r--r--sources/pyside6/doc/tutorials/qmlsqlintegration/qmlsqlintegration.rst97
10 files changed, 237 insertions, 238 deletions
diff --git a/sources/pyside6/doc/tutorials/basictutorial/dialog.rst b/sources/pyside6/doc/tutorials/basictutorial/dialog.rst
index bc06d6d9b..e2512f9db 100644
--- a/sources/pyside6/doc/tutorials/basictutorial/dialog.rst
+++ b/sources/pyside6/doc/tutorials/basictutorial/dialog.rst
@@ -3,8 +3,8 @@ Creating a Dialog Application
This tutorial shows how to build a simple dialog with some
basic widgets. The idea is to let users provide their name
-in a `QLineEdit`, and the dialog greets them on click of a
-`QPushButton`.
+in a ``QLineEdit``, and the dialog greets them on click of a
+``QPushButton``.
Let us just start with a simple stub that creates and shows
a dialog. This stub is updated during the course of this
@@ -31,24 +31,24 @@ tutorial, but you can use this stub as is if you need to:
sys.exit(app.exec())
The imports aren't new to you, the same for the creation of the
-`QApplication` and the execution of the Qt main loop.
+``QApplication`` and the execution of the Qt main loop.
The only novelty here is the **class definition**.
You can create any class that subclasses PySide6 widgets.
-In this case, we are subclassing `QDialog` to define a custom
+In this case, we are subclassing ``QDialog`` to define a custom
dialog, which we name as **Form**. We have also implemented the
-`init()` method that calls the `QDialog`'s init method with the
-parent widget, if any. Also, the new `setWindowTitle()` method
-just sets the title of the dialog window. In `main()`, you can see
+``init()`` method that calls the ``QDialog``'s init method with the
+parent widget, if any. Also, the new ``setWindowTitle()`` method
+just sets the title of the dialog window. In ``main()``, you can see
that we are creating a *Form object* and showing it to the world.
Create the Widgets
------------------
-We are going to create two widgets: a `QLineEdit` where users can
-enter their name, and a `QPushButton` that prints the contents of
-the `QLineEdit`.
-So, let's add the following code to the `init()` method of our Form:
+We are going to create two widgets: a ``QLineEdit`` where users can
+enter their name, and a ``QPushButton`` that prints the contents of
+the ``QLineEdit``.
+So, let's add the following code to the ``init()`` method of our Form:
::
# Create widgets
@@ -62,8 +62,8 @@ Create a layout to organize the Widgets
---------------------------------------
Qt comes with layout-support that helps you organize the widgets
-in your application. In this case, let's use `QVBoxLayout` to lay out
-the widgets vertically. Add the following code to the `init()` method,
+in your application. In this case, let's use ``QVBoxLayout`` to lay out
+the widgets vertically. Add the following code to the ``init()`` method,
after creating the widgets:
::
@@ -72,33 +72,33 @@ after creating the widgets:
layout.addWidget(self.edit)
layout.addWidget(self.button)
-So, we create the layout, add the widgets with `addWidget()`.
+So, we create the layout, add the widgets with ``addWidget()``.
Create the function to greet and connect the Button
---------------------------------------------------
Finally, we just have to add a function to our custom **Form**
and *connect* our button to it. Our function will be a part of
-the Form, so you have to add it after the `init()` function:
+the Form, so you have to add it after the ``init()`` function:
::
# Greets the user
def greetings(self):
print(f"Hello {self.edit.text()}")
-Our function just prints the contents of the `QLineEdit` to the
+Our function just prints the contents of the ``QLineEdit`` to the
python console. We have access to the text by means of the
-`QLineEdit.text()` method.
+``QLineEdit.text()`` method.
Now that we have everything, we just need to *connect* the
-`QPushButton` to the `Form.greetings()` method. To do so, add the
-following line to the `init()` method:
+``QPushButton`` to the ``Form.greetings()`` method. To do so, add the
+following line to the ``init()`` method:
::
# Add button signal to greetings slot
self.button.clicked.connect(self.greetings)
-Once executed, you can enter your name in the `QLineEdit` and watch
+Once executed, you can enter your name in the ``QLineEdit`` and watch
the console for greetings.
Complete code
diff --git a/sources/pyside6/doc/tutorials/basictutorial/qrcfiles.rst b/sources/pyside6/doc/tutorials/basictutorial/qrcfiles.rst
index 5b397bd0b..907afc726 100644
--- a/sources/pyside6/doc/tutorials/basictutorial/qrcfiles.rst
+++ b/sources/pyside6/doc/tutorials/basictutorial/qrcfiles.rst
@@ -1,7 +1,7 @@
.. _using_qrc_files:
-Using `.qrc` Files (`pyside6-rcc`)
-**********************************
+Using ``.qrc`` Files (``pyside6-rcc``)
+**************************************
The `Qt Resource System`_ is a mechanism for storing binary files
in an application.
@@ -17,7 +17,7 @@ In this tutorial you will learn how to load custom images as button icons.
For inspiration, we will try to adapt the multimedia player example
from Qt.
-As you can see on the following image, the `QPushButton` that are used
+As you can see on the following image, the ``QPushButton`` that are used
for the media actions (play, pause, stop, and so on) are using the
default icons meant for such actions.
@@ -31,19 +31,19 @@ and use them.
.. image:: icons.png
:alt: New Multimedia icons
-You can find more information about the `rcc` command, and `.qrc` file
+You can find more information about the ``rcc`` command, and ``.qrc`` file
format, and the resource system in general in the `Qt Resource System`_
site.
.. _`download the following set`: icons/
-The `.qrc` file
-================
+The ``.qrc`` file
+=================
-Before running any command, add information about the resources to a `.qrc`
+Before running any command, add information about the resources to a ``.qrc``
file.
-In the following example, notice how the resources are listed in `icons.qrc`
+In the following example, notice how the resources are listed in ``icons.qrc``
::
@@ -62,15 +62,15 @@ In the following example, notice how the resources are listed in `icons.qrc`
Generating a Python file
=========================
-Now that the `icons.qrc` file is ready, use the `pyside6-rcc` tool to generate
+Now that the ``icons.qrc`` file is ready, use the ``pyside6-rcc`` tool to generate
a Python class containing the binary information about the resources
To do this, we need to run::
pyside6-rcc icons.qrc -o rc_icons.py
-The `-o` option lets you specify the output filename,
-which is `rc_icons.py` in this case.
+The ``-o`` option lets you specify the output filename,
+which is ``rc_icons.py`` in this case.
To use the generated file, add the following import at the top of your main Python file::
@@ -167,7 +167,7 @@ Now, the constructor of your class should look like this:
Executing the example
=====================
-Run the application by calling `python main.py` to checkout the new icon-set:
+Run the application by calling ``python main.py`` to checkout the new icon-set:
.. image:: player-new.png
:alt: New Multimedia Player Qt Example
diff --git a/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst b/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst
index 695f431e1..57e55f5aa 100644
--- a/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst
+++ b/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst
@@ -43,21 +43,21 @@ a signal directly to another signal. (This will emit the second signal
immediately whenever the first is emitted.)
Qt's widgets have many predefined signals and slots. For example,
-`QAbstractButton` (base class of buttons in Qt) has a `clicked()`
-signal and `QLineEdit` (single line input field) has a slot named
-'clear()`. So, a text input field with a button to clear the text
-could be implemented by placing a `QToolButton` to the right of the
-`QLineEdit` and connecting its `clicked()` signal to the slot
-'clear()`. This is done using the `connect()` method of the signal:
+``QAbstractButton`` (base class of buttons in Qt) has a ``clicked()``
+signal and ``QLineEdit`` (single line input field) has a slot named
+``clear()``. So, a text input field with a button to clear the text
+could be implemented by placing a ``QToolButton`` to the right of the
+``QLineEdit`` and connecting its ``clicked()`` signal to the slot
+``clear()``. This is done using the ``connect()`` method of the signal:
- .. code-block:: python
+.. code-block:: python
- button = QToolButton()
- line_edit = QLineEdit()
- button.clicked.connect(line_edit.clear)
+ button = QToolButton()
+ line_edit = QLineEdit()
+ button.clicked.connect(line_edit.clear)
-`connect()` returns a `QMetaObject.Connection` object, which can be
-used with the `disconnect()` method to sever the connection.
+``connect()`` returns a ``QMetaObject.Connection`` object, which can be
+used with the ``disconnect()`` method to sever the connection.
Signals can also be connected to free functions:
@@ -86,7 +86,7 @@ The Signal Class
When writing classes in Python, signals are declared as class level
variables of the class ``QtCore.Signal()``. A QWidget-based button
-that emits a `clicked()` signal could look as
+that emits a ``clicked()`` signal could look as
follows:
.. code-block:: python
@@ -215,7 +215,7 @@ Specifying Signals and Slots by Method Signature Strings
Signals and slots can also be specified as C++ method signature
-strings passed through the `SIGNAL()` and/or `SLOT()` functions:
+strings passed through the ``SIGNAL()`` and/or ``SLOT()`` functions:
.. code-block:: python
@@ -225,7 +225,7 @@ strings passed through the `SIGNAL()` and/or `SLOT()` functions:
action_handler, SLOT("action1(Qt::MouseButton)"))
This is not recommended for connecting signals, it is mostly
-used to specify signals for methods like `QWizardPage::registerField()`:
+used to specify signals for methods like ``QWizardPage::registerField()``:
.. code-block:: python
diff --git a/sources/pyside6/doc/tutorials/basictutorial/translations.rst b/sources/pyside6/doc/tutorials/basictutorial/translations.rst
index 31cd004a3..98a5d94dc 100644
--- a/sources/pyside6/doc/tutorials/basictutorial/translations.rst
+++ b/sources/pyside6/doc/tutorials/basictutorial/translations.rst
@@ -28,18 +28,18 @@ The linguist example has a number of messages enclosed in ``self.tr()``.
The status bar message shown in response to a selection change uses
a plural form depending on a count:
- .. code-block:: python
+.. code-block:: python
- count = len(self._list_widget.selectionModel().selectedRows())
- message = self.tr("%n language(s) selected", "", count)
+ count = len(self._list_widget.selectionModel().selectedRows())
+ message = self.tr("%n language(s) selected", "", count)
The translation workflow for the example is as follows:
The translated messages are extracted using the ``lupdate`` tool,
producing XML-based ``.ts`` files:
- .. code-block:: bash
+.. code-block:: bash
- pyside6-lupdate main.py -ts example_de.ts
+ pyside6-lupdate main.py -ts example_de.ts
If ``example_de.ts`` already exists, it will be updated with the new
messages added to the code in-between.
@@ -52,15 +52,15 @@ they should be passed to the ``pyside6-lupdate`` tool as well:
pyside6-lupdate main.py main.qml form.ui -ts example_de.ts
The source files generated by ``pyside6-uic`` from the form files
-should `not` be passed.
+should **not** be passed.
``.ts`` files are translated using *Qt Linguist*. Once this is complete,
the files are converted to a binary form (``.qm`` files):
- .. code-block:: bash
+.. code-block:: bash
- mkdir translations
- pyside6-lrelease example_de.ts -qm translations/example_de.qm
+ mkdir translations
+ pyside6-lrelease example_de.ts -qm translations/example_de.qm
To avoid having to ship the ``.qm`` files, it is recommend
to put them into a Qt resource file along with icons and other
@@ -68,35 +68,35 @@ applications resources (see :ref:`using_qrc_files`).
The resource file ``linguist.qrc`` provides the ``example_de.qm``
under ``:/translations``:
- .. code-block:: xml
+.. code-block:: xml
- <!DOCTYPE RCC><RCC version="1.0">
- <qresource>
- <file>translations/example_de.qm</file>
- </qresource>
- </RCC>
+ <!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>translations/example_de.qm</file>
+ </qresource>
+ </RCC>
At runtime, the translations need to be loaded using the ``QTranslator`` class:
- .. code-block:: python
+.. code-block:: python
- path = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
- translator = QTranslator(app)
- if translator.load(QLocale.system(), 'qtbase', '_', path):
- app.installTranslator(translator)
- translator = QTranslator(app)
- path = ':/translations'
- if translator.load(QLocale.system(), 'example', '_', path):
- app.installTranslator(translator)
+ path = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
+ translator = QTranslator(app)
+ if translator.load(QLocale.system(), 'qtbase', '_', path):
+ app.installTranslator(translator)
+ translator = QTranslator(app)
+ path = ':/translations'
+ if translator.load(QLocale.system(), 'example', '_', path):
+ app.installTranslator(translator)
The code first loads the translations shipped for Qt and then
the translations of the applications loaded from resources.
The example can then be run in German:
- .. code-block:: bash
+.. code-block:: bash
- LANG=de python main.py
+ LANG=de python main.py
GNU gettext
-----------
@@ -116,29 +116,29 @@ aliased to ``ngettext``.
Those functions are defined at the top:
- .. code-block:: python
+.. code-block:: python
- import gettext
- ...
- _ = None
- ngettext = None
+ import gettext
+ ...
+ _ = None
+ ngettext = None
and later assigned as follows:
- .. code-block:: python
-
- src_dir = Path(__file__).resolve().parent
- try:
- translation = gettext.translation('example', localedir=src_dir / 'locales')
- if translation:
- translation.install()
- _ = translation.gettext
- ngettext = translation.ngettext
- except FileNotFoundError:
- pass
- if not _:
- _ = gettext.gettext
- ngettext = gettext.ngettext
+.. code-block:: python
+
+ src_dir = Path(__file__).resolve().parent
+ try:
+ translation = gettext.translation('example', localedir=src_dir / 'locales')
+ if translation:
+ translation.install()
+ _ = translation.gettext
+ ngettext = translation.ngettext
+ except FileNotFoundError:
+ pass
+ if not _:
+ _ = gettext.gettext
+ ngettext = gettext.ngettext
This specifies that our translation file has the base name ``example`` and
will be found in the source tree under ``locales``. The code will try
@@ -146,18 +146,18 @@ to load a translation matching the current language.
Messages to be translated look like:
- .. code-block:: python
+.. code-block:: python
- file_menu = self.menuBar().addMenu(_("&File"))
+ file_menu = self.menuBar().addMenu(_("&File"))
The status bar message shown in response to a selection change uses
a plural form depending on a count:
- .. code-block:: python
+.. code-block:: python
- count = len(self._list_widget.selectionModel().selectedRows())
- message = ngettext("{0} language selected",
- "{0} languages selected", count).format(count)
+ count = len(self._list_widget.selectionModel().selectedRows())
+ message = ngettext("{0} language selected",
+ "{0} languages selected", count).format(count)
The ``ngettext()`` function takes the singular form, plural form and the count.
The returned string still contains the formatting placeholder, so it needs
@@ -174,41 +174,41 @@ is first created:
This file has a few generic placeholders which can be replaced by the
appropriate values. It is then copied to the ``de_DE/LC_MESSAGES`` directory.
- .. code-block:: bash
+.. code-block:: bash
- cd locales/de_DE/LC_MESSAGES/
- cp ../../example.pot .
+ cd locales/de_DE/LC_MESSAGES/
+ cp ../../example.pot .
Further adaptions need to be made to account for the German plural
form and encoding:
- .. code-block::
+.. code-block::
- "Project-Id-Version: PySide6 gettext example\n"
- "POT-Creation-Date: 2021-07-05 14:16+0200\n"
- "Language: de_DE\n"
- "MIME-Version: 1.0\n"
- "Content-Type: text/plain; charset=UTF-8\n"
- "Content-Transfer-Encoding: 8bit\n"
- "Plural-Forms: nplurals=2; plural=n != 1;\n"
+ "Project-Id-Version: PySide6 gettext example\n"
+ "POT-Creation-Date: 2021-07-05 14:16+0200\n"
+ "Language: de_DE\n"
+ "MIME-Version: 1.0\n"
+ "Content-Type: text/plain; charset=UTF-8\n"
+ "Content-Transfer-Encoding: 8bit\n"
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
Below, the translated messages can be given:
- .. code-block::
+.. code-block::
- #: main.py:57
- msgid "&File"
- msgstr "&Datei"
+ #: main.py:57
+ msgid "&File"
+ msgstr "&Datei"
Finally, the ``.pot`` is converted to its binary form (machine object file,
``.mo``), which needs to be deployed:
- .. code-block:: bash
+.. code-block:: bash
- msgfmt -o example.mo example.pot
+ msgfmt -o example.mo example.pot
The example can then be run in German:
- .. code-block:: bash
+.. code-block:: bash
- LANG=de python main.py
+ LANG=de python main.py
diff --git a/sources/pyside6/doc/tutorials/basictutorial/uifiles.rst b/sources/pyside6/doc/tutorials/basictutorial/uifiles.rst
index cd1057c97..4f2fa1ba5 100644
--- a/sources/pyside6/doc/tutorials/basictutorial/uifiles.rst
+++ b/sources/pyside6/doc/tutorials/basictutorial/uifiles.rst
@@ -1,7 +1,7 @@
.. _using_ui_files:
-Using `.ui` files from Designer or QtCreator with `QUiLoader` and `pyside6-uic`
-*******************************************************************************
+Using ``.ui`` files from Designer or QtCreator with ``QUiLoader`` and ``pyside6-uic``
+*************************************************************************************
This page describes the use of
`Qt Designer <https://doc.qt.io/qt-6/qtdesigner-manual.html>`_ to create
@@ -15,13 +15,13 @@ is described at
.. image:: uifiles.png
:alt: Designer and the equivalent code
-The designs are stored in `.ui` files, which is an XML-based format. It will
+The designs are stored in ``.ui`` files, which is an XML-based format. It will
be converted to Python or C++ code populating a widget instance at project build
time by the `pyside6-uic <https://doc.qt.io/qt-6/uic.html>`_ tool.
To create a new Qt Design Form in **Qt Creator**, choose
-`File/New File Or Project` and "Main Window" for template. Save it as
-`mainwindow.ui`. Add a `QPushButton` to the center of the centralwidget.
+``File/New File Or Project`` and "Main Window" for template. Save it as
+``mainwindow.ui``. Add a ``QPushButton`` to the center of the centralwidget.
Your file ``mainwindow.ui`` should look something like this:
@@ -88,12 +88,12 @@ Option A: Generating a Python class
===================================
The standard way to interact with a **UI file** is to generate a Python
-class from it. This is possible thanks to the `pyside6-uic` tool.
+class from it. This is possible thanks to the ``pyside6-uic`` tool.
To use this tool, you need to run the following command on a console::
- pyside6-uic mainwindow.ui > ui_mainwindow.py
+ pyside6-uic mainwindow.ui -o ui_mainwindow.py
-We redirect all the output of the command to a file called `ui_mainwindow.py`,
+We redirect all the output of the command to a file called ``ui_mainwindow.py``,
which will be imported directly::
from ui_mainwindow import Ui_MainWindow
@@ -136,7 +136,7 @@ file:
.. note::
- You must run `pyside6-uic` again every time you make changes
+ You must run ``pyside6-uic`` again every time you make changes
to the **UI file**.
Option B: Loading it directly
@@ -149,7 +149,7 @@ module:
from PySide6.QtUiTools import QUiLoader
-The `QUiLoader` lets us load the **ui file** dynamically
+The ``QUiLoader`` lets us load the **ui file** dynamically
and use it right away:
.. code-block:: python
@@ -198,9 +198,9 @@ command prompt:
.. note::
- `QUiLoader` uses connect() calls taking the function signatures as string
+ ``QUiLoader`` uses ``connect()`` calls taking the function signatures as string
arguments for signal/slot connections.
- It is thus unable to handle Python types like `str` or `list` from
+ It is thus unable to handle Python types like ``str`` or ``list`` from
custom widgets written in Python since these types are internally mapped
to different C++ types.
@@ -270,7 +270,7 @@ for registering types or adding instances of
The function
:meth:`registerCustomWidget()<PySide6.QtDesigner.QPyDesignerCustomWidgetCollection.registerCustomWidget>`
is used to register a widget type with **Qt Designer**. In the simple case, it
-can be used like `QUiLoader.registerCustomWidget()`. It takes the custom widget
+can be used like ``QUiLoader.registerCustomWidget()``. It takes the custom widget
type and some optional keyword arguments passing values that correspond to the
getters of
`QDesignerCustomWidgetInterface <https://doc.qt.io/qt-6/qdesignercustomwidgetinterface.html>`_ :
diff --git a/sources/pyside6/doc/tutorials/basictutorial/widgetstyling.rst b/sources/pyside6/doc/tutorials/basictutorial/widgetstyling.rst
index e1af8b8a9..2fa51c0a8 100644
--- a/sources/pyside6/doc/tutorials/basictutorial/widgetstyling.rst
+++ b/sources/pyside6/doc/tutorials/basictutorial/widgetstyling.rst
@@ -23,7 +23,7 @@ to each component. As an example, look at the following simple snippet:
w.show()
sys.exit(app.exec())
-When you execute this code, you will see a simple `QLabel` aligned at the
+When you execute this code, you will see a simple ``QLabel`` aligned at the
center, and with a placeholder text.
.. image:: widgetstyling-simple-no.png
@@ -32,8 +32,8 @@ center, and with a placeholder text.
You can style your application using the CSS-like syntax.
For more information, see `Qt Style Sheets Reference`_.
-A `QLabel` can be styled differently by setting some of its CSS
-properties, such as `background-color` and `font-family`,
+A ``QLabel`` can be styled differently by setting some of its CSS
+properties, such as ``background-color`` and ``font-family``,
so let's see how does the code look like with these changes:
.. code-block:: python
@@ -55,7 +55,7 @@ so let's see how does the code look like with these changes:
w.show()
sys.exit(app.exec())
-Now when you run the code, notice that the `QLabel` looks different with your
+Now when you run the code, notice that the ``QLabel`` looks different with your
custom style:
.. image:: widgetstyling-simple-yes.png
@@ -64,15 +64,15 @@ custom style:
.. note::
- If you don't have the font `Titillium` installed, you can try with any
+ If you don't have the font ``Titillium`` installed, you can try with any
other you prefer.
- Remember you can list your installed fonts using `QFontDatabase`,
- specifically the `families()` method.
+ Remember you can list your installed fonts using ``QFontDatabase``,
+ specifically the ``families()`` method.
Styling each UI element separately like you did in the previous snippet is a
lot of work. The easier alternative for this is to use Qt Style Sheets,
-which is one or more `.qss` files defining the style for the UI elements in
+which is one or more ``.qss`` files defining the style for the UI elements in
your application.
More examples can be found in the `Qt Style Sheet Examples`_ documentation
@@ -94,7 +94,7 @@ Qt Style Sheets
It's recommended to create a full new Qt style to cover all the possible
corner cases.
-A `qss` file is quite similar to a CSS file, but you need to specify the Widget
+A ``qss`` file is quite similar to a CSS file, but you need to specify the Widget
component and optionally the name of the object::
QLabel {
@@ -105,8 +105,8 @@ component and optionally the name of the object::
font-size: 20px;
}
-The first style defines a `background-color` for all `QLabel` objects in your
-application, whereas the later one styles the `title` object only.
+The first style defines a ``background-color`` for all ``QLabel`` objects in your
+application, whereas the later one styles the ``title`` object only.
.. note::
@@ -115,8 +115,8 @@ application, whereas the later one styles the `title` object only.
`label.setObjectName("title")`
-Once you have a `qss` file for your application, you can apply it by reading
-the file and using the `QApplication.setStyleSheet(str)` function:
+Once you have a ``qss`` file for your application, you can apply it by reading
+the file and using the ``QApplication.setStyleSheet(str)`` function:
.. code-block:: python
@@ -132,7 +132,7 @@ the file and using the `QApplication.setStyleSheet(str)` function:
sys.exit(app.exec())
-Having a general `qss` file allows you to decouple the styling aspects of
+Having a general ``qss`` file allows you to decouple the styling aspects of
the code, without mixing it in the middle of the general functionality, and you
can simply enable it or disable it.
@@ -142,14 +142,14 @@ Look at this new example, with more widgets components:
:linenos:
:lines: 22-44
-This displays a two column widget, with a `QListWidget` on the left and a
-`QLabel` and a `QPushButton` on the right. It looks like this when you run the
+This displays a two column widget, with a ``QListWidget`` on the left and a
+``QLabel`` and a ``QPushButton`` on the right. It looks like this when you run the
code:
.. image:: widgetstyling-no.png
:alt: Widget with no style
-If you add content to the previously described `style.qss` file, you can modify
+If you add content to the previously described ``style.qss`` file, you can modify
the look-n-feel of the previous example:
.. literalinclude:: style.qss
@@ -161,7 +161,7 @@ You can also use state-based styling on the QListWidget *items* for example, to
style them differently depending on whether they are *selected* or not.
After applying all the styling alternatives you explored in this topic, notice
-that the `QLabel` example looks a lot different now.
+that the ``QLabel`` example looks a lot different now.
Try running the code to check its new look:
.. image:: widgetstyling-yes.png
diff --git a/sources/pyside6/doc/tutorials/debugging/qtcreator/qtcreator.rst b/sources/pyside6/doc/tutorials/debugging/qtcreator/qtcreator.rst
index c8c9fb8ae..a35020fd1 100644
--- a/sources/pyside6/doc/tutorials/debugging/qtcreator/qtcreator.rst
+++ b/sources/pyside6/doc/tutorials/debugging/qtcreator/qtcreator.rst
@@ -14,26 +14,26 @@ Here are the steps:
2. Go to Projects -> Run -> Run Configuration -> Add. This is going to open a
new window shown below.
- .. image:: custom_executable_create.png
- :alt: creation of custom executable
- :align: center
+ .. image:: custom_executable_create.png
+ :alt: creation of custom executable
+ :align: center
3. Click on Custom Executable and `Create` a new configuration. Feed in the
-details like shown below.
+ details like shown below.
- .. image:: custom_executable_run_config.png
- :alt: run configuration of custom executable
- :align: center
+ .. image:: custom_executable_run_config.png
+ :alt: run configuration of custom executable
+ :align: center
4. Debug -> Start Debugging -> Start Debugging Without Deployment.
- .. image:: start_debugging_without_deployment.png
- :alt: start debugging without deployment
- :align: center
+ .. image:: start_debugging_without_deployment.png
+ :alt: start debugging without deployment
+ :align: center
You will now hit you breakpoint and can start debugging your code.
- .. image:: breakpoint_cpp.png
- :alt: breakpoint cpp
- :align: center
+.. image:: breakpoint_cpp.png
+ :alt: breakpoint cpp
+ :align: center
diff --git a/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst b/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst
index 806035299..b2a527b0e 100644
--- a/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst
+++ b/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst
@@ -36,7 +36,7 @@ search for "Python: Select Interpreter".
Creating Configurations in launch.json
--------------------------------------
-Run -> Add Configuration -> Python -> Python File
+``Run -> Add Configuration -> Python -> Python File``
This should create a launch.json file which looks like this:
@@ -145,7 +145,7 @@ Debug The Process
1. Set a breakpoint in the Python code.
-2. Go to `Run And Debug` (Ctrl + Shift + D) and run the "Python: Current File"
+2. Go to ``Run And Debug`` (Ctrl + Shift + D) and run the "Python: Current File"
by clicking the run symbol (green right-arrow). This will hit the breakpoint
and will halt the Python debugger.
@@ -153,40 +153,40 @@ Debug The Process
Current File" to "(gdb) Attach" or "(Windows) Attach". Your setup should now
look like this.
- .. image:: breakpoint_gdb.png
- :alt: breakpoint before attach gdb
- :align: center
+ .. image:: breakpoint_gdb.png
+ :alt: breakpoint before attach gdb
+ :align: center
4. Run "(gdb) Attach" or "(Windows) Attach" and this should ask you for the
processId of the Python process to which you want to attach the C++ debugger.
VSCode also lets you search for the process by its name.
- .. tip:: You can find the processId by running `ps aux | grep python`
+ .. tip:: You can find the processId by running ``ps aux | grep python``
- .. image:: find_process_gdb.png
- :alt: find process vscode
- :align: center
+ .. image:: find_process_gdb.png
+ :alt: find process vscode
+ :align: center
5. VSCode might now ask you for superuser permissions. In that case, type 'y'
and enter your password.
- .. code-block:: bash
+ .. code-block:: bash
- Superuser access is required to attach to a process. Attaching as
- superuser can potentially harm your computer. Do you want to continue?
- [y/N]_
+ Superuser access is required to attach to a process. Attaching as
+ superuser can potentially harm your computer. Do you want to continue?
+ [y/N]_
6. That is it. You should now be able to hit the breakpoints that you have set
on the C++ counterparts.
- .. figure:: audioformat_wrapper.png
- :alt: Breakpoint set on the shiboken wrapper class
- :align: left
+ .. figure:: audioformat_wrapper.png
+ :alt: Breakpoint set on the shiboken wrapper class
+ :align: left
- Breakpoint set on the shiboken wrapper class
+ Breakpoint set on the shiboken wrapper class
- .. figure:: audioformat_cpp.png
- :alt: Breakpoint set on C++ implementation
- :align: left
+ .. figure:: audioformat_cpp.png
+ :alt: Breakpoint set on C++ implementation
+ :align: left
- Breakpoint set on C++ implementation
+ Breakpoint set on C++ implementation
diff --git a/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst b/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst
index 9520f0b5d..c60566fd5 100644
--- a/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst
+++ b/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst
@@ -35,7 +35,7 @@ application and PySide6 integration:
Notice that we only need a :code:`QQmlApplicationEngine` to
:code:`load` the QML file.
-#. Define the `Bridge` class, containing all the logic for the element
+#. Define the ``Bridge`` class, containing all the logic for the element
that will be register in QML:
.. literalinclude:: main.py
@@ -48,7 +48,7 @@ application and PySide6 integration:
class and the variables :code:`QML_IMPORT_NAME` and
:code:`QML_IMPORT_MAJOR_VERSION`.
-#. Now, go back to the QML file and connect the signals to the slots defined in the `Bridge` class:
+#. Now, go back to the QML file and connect the signals to the slots defined in the ``Bridge`` class:
.. code:: js
@@ -95,22 +95,22 @@ application and PySide6 integration:
#. Now, for changing the look of our application, you have two options:
- 1. Use the command line: execute the python file adding the option, `--style`::
+ 1. Use the command line: execute the python file adding the option, ``--style``::
python main.py --style material
- 2. Use a `qtquickcontrols2.conf` file:
+ 2. Use a ``qtquickcontrols2.conf`` file:
.. literalinclude:: qtquickcontrols2.conf
:linenos:
- Then add it to your `.qrc` file:
+ Then add it to your ``.qrc`` file:
.. literalinclude:: style.qrc
:linenos:
- Generate the *rc* file running, `pyside6-rcc style.qrc -o style_rc.py`
- And finally import it from your `main.py` script.
+ Generate the *rc* file running, ``pyside6-rcc style.qrc -o style_rc.py``
+ And finally import it from your ``main.py`` script.
.. literalinclude:: main.py
:linenos:
diff --git a/sources/pyside6/doc/tutorials/qmlsqlintegration/qmlsqlintegration.rst b/sources/pyside6/doc/tutorials/qmlsqlintegration/qmlsqlintegration.rst
index 4c0131f32..c664f2e46 100644
--- a/sources/pyside6/doc/tutorials/qmlsqlintegration/qmlsqlintegration.rst
+++ b/sources/pyside6/doc/tutorials/qmlsqlintegration/qmlsqlintegration.rst
@@ -14,9 +14,9 @@ name of our table, and define the global function ``createTable()`` that creates
doesn't already exist.
The database contains a single line to mock the beginning of a conversation.
- .. literalinclude:: sqlDialog.py
- :linenos:
- :lines: 3-42
+.. literalinclude:: sqlDialog.py
+ :linenos:
+ :lines: 4-43
The ``SqlConversationModel`` class offers the read-only data model required for the non-editable
contacts list. It derives from the :ref:`QSqlQueryModel` class, which is the logical choice for
@@ -26,25 +26,25 @@ Then, we proceed to create the table, set its name to the one defined previously
We add the necessary attributes to the table, to have a program that reflects the idea
of a chat application.
- .. literalinclude:: sqlDialog.py
- :linenos:
- :lines: 46-58
+.. literalinclude:: sqlDialog.py
+ :linenos:
+ :lines: 47-59
In ``setRecipient()``, you set a filter over the returned results from the database, and
emit a signal every time the recipient of the message changes.
- .. literalinclude:: sqlDialog.py
- :linenos:
- :lines: 60-69
+.. literalinclude:: sqlDialog.py
+ :linenos:
+ :lines: 61-70
The ``data()`` function falls back to ``QSqlTableModel``'s implementation if the role is not a
custom user role.
If you get a user role, we can subtract :meth:`~.QtCore.Qt.UserRole` from it to get the index of
that field, and then use that index to find the value to be returned.
- .. literalinclude:: sqlDialog.py
- :linenos:
- :lines: 71-78
+.. literalinclude:: sqlDialog.py
+ :linenos:
+ :lines: 72-79
In ``roleNames()``, we return a Python dictionary with our custom role and role names as key-values
@@ -53,27 +53,27 @@ Alternatively, it can be useful to declare an Enum to hold all of the role value
Note that ``names`` has to be a hash to be used as a dictionary key,
and that's why we're using the ``hash`` function.
- .. literalinclude:: sqlDialog.py
- :linenos:
- :lines: 80-94
+.. literalinclude:: sqlDialog.py
+ :linenos:
+ :lines: 81-95
The ``send_message()`` function uses the given recipient and message to insert a new record into
the database.
Using :meth:`~.QSqlTableModel.OnManualSubmit` requires you to also call ``submitAll()``,
since all the changes will be cached in the model until you do so.
- .. literalinclude:: sqlDialog.py
- :linenos:
- :lines: 96-115
+.. literalinclude:: sqlDialog.py
+ :linenos:
+ :lines: 97-116
chat.qml
--------
Let's look at the ``chat.qml`` file.
- .. literalinclude:: chat.qml
- :linenos:
- :lines: 3-5
+.. literalinclude:: chat.qml
+ :linenos:
+ :lines: 4-6
First, import the Qt Quick module.
This gives us access to graphical primitives such as Item, Rectangle, Text, and so on.
@@ -86,9 +86,9 @@ root type, Window:
Let's step through the ``chat.qml`` file.
- .. literalinclude:: chat.qml
- :linenos:
- :lines: 8-13
+.. literalinclude:: chat.qml
+ :linenos:
+ :lines: 9-14
``ApplicationWindow`` is a Window with some added convenience for creating a header and a footer.
It also provides the foundation for popups and supports some basic styling, such as the background
@@ -101,9 +101,9 @@ Once we've set these, we have a properly sized, empty window ready to be filled
Because we are exposing the :code:`SqlConversationModel` class to QML, we will
declare a component to access it:
- .. literalinclude:: chat.qml
- :linenos:
- :lines: 15-17
+.. literalinclude:: chat.qml
+ :linenos:
+ :lines: 16-18
There are two ways of laying out items in QML: `Item Positioners`_ and `Qt Quick Layouts`_.
@@ -113,13 +113,13 @@ There are two ways of laying out items in QML: `Item Positioners`_ and `Qt Quick
resizable user interfaces.
Below, we use `ColumnLayout`_ to vertically lay out a `ListView`_ and a `Pane`_.
- .. literalinclude:: chat.qml
- :linenos:
- :lines: 19-22
+ .. literalinclude:: chat.qml
+ :linenos:
+ :lines: 20-23
- .. literalinclude:: chat.qml
- :linenos:
- :lines: 71-73
+ .. literalinclude:: chat.qml
+ :linenos:
+ :lines: 72-74
Pane is basically a rectangle whose color comes from the application's style.
It's similar to `Frame`_, but it has no stroke around its border.
@@ -149,13 +149,12 @@ remaining space that is left after accommodating the Pane.
Let's look at the ``Listview`` in detail:
- .. literalinclude:: chat.qml
- :linenos:
- :lines: 22-69
+.. literalinclude:: chat.qml
+ :linenos:
+ :lines: 23-70
After filling the ``width`` and ``height`` of its parent, we also set some margins on the view.
-
Next, we set `displayMarginBeginning`_ and `displayMarginEnd`_.
These properties ensure that the delegates outside the view don't disappear when you
scroll at the edges of the view.
@@ -179,9 +178,9 @@ At the bottom of the screen, we place a `TextArea`_ item to allow multi-line tex
button to send the message.
We use Pane to cover the area under these two items:
- .. literalinclude:: chat.qml
- :linenos:
- :lines: 71-95
+.. literalinclude:: chat.qml
+ :linenos:
+ :lines: 72-96
The `TextArea`_ should fill the available width of the screen.
We assign some placeholder text to provide a visual cue to the contact as to where they should begin
@@ -203,16 +202,16 @@ main.py
We use ``logging`` instead of Python's ``print()``, because it provides a better way to control the
messages levels that our application will generate (errors, warnings, and information messages).
- .. literalinclude:: main.py
- :linenos:
- :lines: 3-15
+.. literalinclude:: main.py
+ :linenos:
+ :lines: 4-16
``connectToDatabase()`` creates a connection with the SQLite database, creating the actual file
if it doesn't already exist.
- .. literalinclude:: main.py
- :linenos:
- :lines: 18-38
+.. literalinclude:: main.py
+ :linenos:
+ :lines: 19-39
A few interesting things happen in the ``main`` function:
@@ -227,8 +226,8 @@ A few interesting things happen in the ``main`` function:
Finally, the Qt application runs, and your program starts.
- .. literalinclude:: main.py
- :linenos:
- :lines: 41-51
+.. literalinclude:: main.py
+ :linenos:
+ :lines: 42-52
.. image:: example_list_view.png