PySide: Difference between revisions
(Created page with "{{Docnav |Pivy |Interface creation }} {{TOCright}} ==Introduction== The PySide library gives access to the cross-platform graphical user interface (GUI) toolkit Qt from Python. Qt is a collection of C++ libraries, but with the help of PySide, the same components can be used from Python. Every graphical interface that can be created in C++, can also be created and modified in Python. An advantage of usin...") |
No edit summary |
||
Line 10: | Line 10: | ||
The [[PySide|PySide]] library gives access to the cross-platform graphical user interface (GUI) toolkit Qt from [[Python|Python]]. Qt is a collection of C++ libraries, but with the help of PySide, the same components can be used from [[Python|Python]]. Every graphical interface that can be created in C++, can also be created and modified in Python. An advantage of using Python is that Qt interfaces can be developed and tested live, as we don't need to compile the source files. | The [[PySide|PySide]] library gives access to the cross-platform graphical user interface (GUI) toolkit Qt from [[Python|Python]]. Qt is a collection of C++ libraries, but with the help of PySide, the same components can be used from [[Python|Python]]. Every graphical interface that can be created in C++, can also be created and modified in Python. An advantage of using Python is that Qt interfaces can be developed and tested live, as we don't need to compile the source files. | ||
When you install | When you install LabRPS, you should get both Qt and PySide as part of the package. If you are [[Compiling|compiling]] yourself then you must verify that these two libraries are installed in order for LabRPS to run correctly. Of course, PySide will only work if Qt is present. | ||
In the past, | In the past, LabRPS used PyQt, another Qt binding for Python, but in 2013 ([https://github.com/LabRPS/LabRPS/commit/1dc122dc9a commit 1dc122dc9a]) the project migrated to PySide because it has a more permissible [[License|License]]. | ||
For more information see: | For more information see: | ||
Line 22: | Line 22: | ||
{{Caption|Examples created with PySide. Left: a simple dialog. Right: a more complex dialog with graphs.}} | {{Caption|Examples created with PySide. Left: a simple dialog. Right: a more complex dialog with graphs.}} | ||
==PySide in | ==PySide in LabRPS with Qt5== | ||
LabRPS was developed to be used with Python 2 and Qt4. As these two libraries became obsolete, LabRPS transitioned to Python 3 and Qt5. In most cases this transition was done without needing to break backwards compatibility. | |||
Normally, the {{incode|PySide}} module provides support for Qt4, while {{incode|PySide2}} provides support for Qt5. However, in | Normally, the {{incode|PySide}} module provides support for Qt4, while {{incode|PySide2}} provides support for Qt5. However, in LabRPS there is no need to use {{incode|PySide2}} directly, as a special {{incode|PySide}} module is included to handle Qt5. | ||
This {{incode|PySide}} module is located in the {{incode|Ext/}} directory of an installation of | This {{incode|PySide}} module is located in the {{incode|Ext/}} directory of an installation of LabRPS compiled for Qt5. | ||
{{Code|code= | {{Code|code= | ||
Line 55: | Line 55: | ||
* [[PySide_Advanced_Examples|PySide Advanced Examples]], many widgets. | * [[PySide_Advanced_Examples|PySide Advanced Examples]], many widgets. | ||
The examples of PySide are divided into 3 parts, differentiated by level of exposure to PySide, Python and the | The examples of PySide are divided into 3 parts, differentiated by level of exposure to PySide, Python and the LabRPS internals. The first page has an overview on PySide; the second and third pages are mostly code examples at different levels. | ||
It is expected that these examples are useful to get started, and afterwards the user can consult other resources online, or the official documentation. | It is expected that these examples are useful to get started, and afterwards the user can consult other resources online, or the official documentation. |
Latest revision as of 09:49, 26 July 2024
Introduction
The PySide library gives access to the cross-platform graphical user interface (GUI) toolkit Qt from Python. Qt is a collection of C++ libraries, but with the help of PySide, the same components can be used from Python. Every graphical interface that can be created in C++, can also be created and modified in Python. An advantage of using Python is that Qt interfaces can be developed and tested live, as we don't need to compile the source files.
When you install LabRPS, you should get both Qt and PySide as part of the package. If you are compiling yourself then you must verify that these two libraries are installed in order for LabRPS to run correctly. Of course, PySide will only work if Qt is present.
In the past, LabRPS used PyQt, another Qt binding for Python, but in 2013 (commit 1dc122dc9a) the project migrated to PySide because it has a more permissible License.
For more information see:
Examples created with PySide. Left: a simple dialog. Right: a more complex dialog with graphs.
PySide in LabRPS with Qt5
LabRPS was developed to be used with Python 2 and Qt4. As these two libraries became obsolete, LabRPS transitioned to Python 3 and Qt5. In most cases this transition was done without needing to break backwards compatibility.
Normally, the PySide
module provides support for Qt4, while PySide2
provides support for Qt5. However, in LabRPS there is no need to use PySide2
directly, as a special PySide
module is included to handle Qt5.
This PySide
module is located in the Ext/
directory of an installation of LabRPS compiled for Qt5.
/usr/share/freecad/Ext/PySide
This module just imports the necessary classes from PySide2
, and places them in the PySide
namespace. This means that in most cases the same code can be used with both Qt4 and Qt5, as long as we use the single PySide
module.
PySide2.QtCore -> PySide.QtCore PySide2.QtGui -> PySide.QtGui PySide2.QtSvg -> PySide.QtSvg PySide2.QtUiTools -> PySide.QtUiTools
The only unusual aspect is that the PySide2.QtWidgets
classes are placed in the PySide.QtGui
namespace.
PySide2.QtWidgets.QCheckBox -> PySide.QtGui.QCheckBox
Examples of PySide use
- PySide Beginner Examples, hello world, announcements, enter text, enter number.
- PySide Intermediate Examples, window sizing, hiding widgets, popup menus, mouse position, mouse events.
- PySide Advanced Examples, many widgets.
The examples of PySide are divided into 3 parts, differentiated by level of exposure to PySide, Python and the LabRPS internals. The first page has an overview on PySide; the second and third pages are mostly code examples at different levels.
It is expected that these examples are useful to get started, and afterwards the user can consult other resources online, or the official documentation.
Documentation
There are some differences in handling of widgets in Qt4 (PySide) and Qt5 (PySide2). The programmer should be aware of these incompatibilities, and should consult the official documentation if something doesn't seem to work as expected on a given platform. Nevertheless, Qt4 is considered obsolete, so most development should target Qt5 and Python 3.
The PySide documentation refers to the Python-style classes; however, since Qt is originally a C++ library, the same information should be available in the corresponding C++ reference.
- Qt Modules available from PySide2 (Qt5).
- All Qt classes by module in Qt5 for C++.
- Qt Modules available from PySide (Qt4).
- LabRPS scripting: Python, Introduction to Python, Python scripting tutorial, LabRPS Scripting Basics
- Modules: Units, Quantity
- Workbenches: Gui Commands, Commands
- Parametric objects: Scripted objects, Viewproviders
- Graphical interface: Interface creation, Interface creation completely in Python, PySide, PySide examples beginner, intermediate, advanced
- Macros: Macros, How to install macros
- Other: Expressions
- Hubs: User hub, Power users hub, Developer hub