diff options
Diffstat (limited to 'sources/pyside6/doc/quickstart.rst')
-rw-r--r-- | sources/pyside6/doc/quickstart.rst | 113 |
1 files changed, 60 insertions, 53 deletions
diff --git a/sources/pyside6/doc/quickstart.rst b/sources/pyside6/doc/quickstart.rst index abff035a5..14d1c03a0 100644 --- a/sources/pyside6/doc/quickstart.rst +++ b/sources/pyside6/doc/quickstart.rst @@ -11,38 +11,39 @@ Before you can install |project|, first you must install the following software: `venv <https://docs.python.org/3/library/venv.html>`_ or `virtualenv <https://virtualenv.pypa.io/en/latest>`_ -Creating and activating an environment --------------------------------------- - -You can do this by running the following on a terminal:: +Installation +------------ - $ python -m venv env/ # Your binary is maybe called 'python3' - $ source env/bin/activate # for Linux and macOS - $ env\Scripts\activate.bat # for Windows +.. raw:: html + <img src="https://qt-wiki-uploads.s3.amazonaws.com/images/8/8a/Pyside6_install.gif" + style="float: right; width: 35%; padding-left: 20px;" + alt="PySide6 installation animation" /> -Installation ------------- +* **Creating and activating an environment** + You can do this by running the following on a terminal: -Now you are ready to install the |project| packages using ``pip``. -From the terminal, run the following command:: + * :command:`python -m venv env`, (Your Python executable might be called ``python3``) + * :command:`source env/bin/activate` for Linux and macOS + * :command:`env\\\Scripts\\\activate.bat` for Windows - # For the latest version on PyPi - pip install PySide6 +* **Installation** - # For a specific version - pip install PySide6==6.0 + Now you are ready to install the |project| packages using ``pip``. + From the terminal, run the following command: -or:: + * :command:`pip install pyside6`, for the latest version. + * :command:`pip install pyside6==6.0`, for the version ``6.0`` specifically. + * It is also possible to install a specific snapshot from our servers. + To do so, you can use the following command:: - pip install --index-url=http://download.qt.io/snapshots/ci/pyside/6.0.0/latest pyside6 --trusted-host download.qt.io + pip install --index-url=http://download.qt.io/snapshots/ci/pyside/6.0.0/latest pyside6 --trusted-host download.qt.io -Test your Installation ----------------------- +* **Test your installation** -Now that you have |project| installed, you can test your setup by running the following Python -constructs to print version information:: + Now that you have |project| installed, test your setup by running the following Python + constructs to print version information:: import PySide6.QtCore @@ -52,7 +53,6 @@ constructs to print version information:: # Prints the Qt version used to compile PySide6 print(PySide6.QtCore.__version__) - Create a Simple Application --------------------------- @@ -60,54 +60,61 @@ Your |project| setup is ready. You can explore it further by developing a simple that prints "Hello World" in several languages. The following instructions will guide you through the development process: -1. Create a new file named :code:`hello_world.py`, and add the following imports to it.:: +* **Imports** + + Create a new file named :code:`hello_world.py`, and add the following imports to it.:: - import sys - import random - from PySide6 import QtCore, QtWidgets, QtGui + import sys + import random + from PySide6 import QtCore, QtWidgets, QtGui The |pymodname| Python module provides access to the Qt APIs as its submodule. In this case, you are importing the :code:`QtCore`, :code:`QtWidgets`, and :code:`QtGui` submodules. -2. Define a class named :code:`MyWidget`, which extends QWidget and includes a QPushButton and - QLabel.:: +* **Main Class** + + Define a class named :code:`MyWidget`, which extends QWidget and includes a QPushButton and + QLabel.:: - class MyWidget(QtWidgets.QWidget): - def __init__(self): - super().__init__() + class MyWidget(QtWidgets.QWidget): + def __init__(self): + super().__init__() - self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"] + self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"] - self.button = QtWidgets.QPushButton("Click me!") - self.text = QtWidgets.QLabel("Hello World", - alignment=QtCore.Qt.AlignCenter) + self.button = QtWidgets.QPushButton("Click me!") + self.text = QtWidgets.QLabel("Hello World", + alignment=QtCore.Qt.AlignCenter) - self.layout = QtWidgets.QVBoxLayout() - self.layout.addWidget(self.text) - self.layout.addWidget(self.button) - self.setLayout(self.layout) + self.layout = QtWidgets.QVBoxLayout(self) + self.layout.addWidget(self.text) + self.layout.addWidget(self.button) - self.button.clicked.connect(self.magic) + self.button.clicked.connect(self.magic) - @QtCore.Slot() - def magic(self): - self.text.setText(random.choice(self.hello)) + @QtCore.Slot() + def magic(self): + self.text.setText(random.choice(self.hello)) The MyWidget class has the :code:`magic` member function that randomly chooses an item from the :code:`hello` list. When you click the button, the :code:`magic` function is called. -3. Now, add a main function where you instantiate :code:`MyWidget` and :code:`show` it.:: +* **Application execution** + + Now, add a main function where you instantiate :code:`MyWidget` and :code:`show` it.:: + + if __name__ == "__main__": + app = QtWidgets.QApplication([]) - if __name__ == "__main__": - app = QtWidgets.QApplication([]) + widget = MyWidget() + widget.resize(800, 600) + widget.show() - widget = MyWidget() - widget.resize(800, 600) - widget.show() + sys.exit(app.exec_()) - sys.exit(app.exec_()) + Run your example by writing the following command: :command:`python hello_world.py`. -Run your example. Try clicking the button at the bottom to see which greeting you get. + Try clicking the button at the bottom to see which greeting you get. -.. image:: pyside-examples/images/screenshot_hello.png - :alt: Hello World application + .. image:: pyside-examples/images/screenshot_hello.png + :alt: Hello World application |