{"id":11678,"date":"2025-02-13T10:00:00","date_gmt":"2025-02-13T09:00:00","guid":{"rendered":"https:\/\/www.basyskom.de\/?p=11678"},"modified":"2025-05-28T11:41:24","modified_gmt":"2025-05-28T09:41:24","slug":"pyside6-qt-for-python","status":"publish","type":"post","link":"https:\/\/www.basyskom.de\/en\/pyside6-qt-for-python\/","title":{"rendered":"PySide6, Qt for Python"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"11678\" class=\"elementor elementor-11678\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1f04815 e-flex e-con-boxed wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-column-slider-no wpr-equal-height-no e-con e-parent\" data-id=\"1f04815\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1e4f327 elementor-widget elementor-widget-text-editor\" data-id=\"1e4f327\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Interested in Qt for Python? Let me tell you what I learned during the past couple of months using it. I\u2019ve had the opportunity to work on a project based on\u00a0PySide6, the official Python bindings for Qt 6. I\u2019ve always wanted to get more familiar with Python, so combining that with Qt, something I\u2019m deeply familiar with, was the perfect chance to do so.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0536c62 elementor-widget elementor-widget-image\" data-id=\"0536c62\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"271\" src=\"https:\/\/www.basyskom.de\/wp-content\/uploads\/2025\/02\/hello-pyside-1024x347.png\" class=\"attachment-large size-large wp-image-11683\" alt=\"basysKom, HMI Dienstleistung, Qt, Cloud, Azure\" srcset=\"https:\/\/www.basyskom.de\/wp-content\/uploads\/2025\/02\/hello-pyside-1024x347.png 1024w, https:\/\/www.basyskom.de\/wp-content\/uploads\/2025\/02\/hello-pyside-300x102.png 300w, https:\/\/www.basyskom.de\/wp-content\/uploads\/2025\/02\/hello-pyside-768x261.png 768w, https:\/\/www.basyskom.de\/wp-content\/uploads\/2025\/02\/hello-pyside-18x6.png 18w, https:\/\/www.basyskom.de\/wp-content\/uploads\/2025\/02\/hello-pyside-560x190.png 560w, https:\/\/www.basyskom.de\/wp-content\/uploads\/2025\/02\/hello-pyside.png 1117w\" sizes=\"(max-width: 800px) 100vw, 800px\">\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-059b940 elementor-widget elementor-widget-text-editor\" data-id=\"059b940\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Setting up PySide6 is easy, just create a new virtual environment, activate it, and then install <code data-no-translation=\"\">pyside6<\/code> through <code data-no-translation=\"\">pip<\/code>. This installs the latest and greatest Qt version together with all the necessary tools. For every Qt tool, there\u2019s a PySide equivalent: <code data-no-translation=\"\">pyside6-lupdate<\/code>, <code data-no-translation=\"\">pyside6-lrelease<\/code>, <code data-no-translation=\"\">pyside6-rcc<\/code>, and so on.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4ee3c37 elementor-widget elementor-widget-elementor-syntax-highlighter\" data-id=\"4ee3c37\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"elementor-syntax-highlighter.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre data-no-translation=\"\"><code class='language-solid' data-no-translation=\"\">python -m venv env\nsource env\/bin\/activate\npip install pyside6 <\/code><\/pre><script>\nif (!document.getElementById('syntaxed-prism')) {\n\tvar my_awesome_script = document.createElement('script');\n\tmy_awesome_script.setAttribute('src','https:\/\/www.basyskom.de\/wp-content\/plugins\/syntax-highlighter-for-elementor\/assets\/prism2.js');\n\tmy_awesome_script.setAttribute('id','syntaxed-prism');\n\tdocument.body.appendChild(my_awesome_script);\n} else {\n\twindow.Prism && Prism.highlightAll();\n}\n<\/script>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c48d62 elementor-widget elementor-widget-text-editor\" data-id=\"8c48d62\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>There\u2019s also a <code data-no-translation=\"\">pyside6-uic<\/code> that takes a UI file created in Qt Designer and creates code from it. Unlike its C++ counterpart, the PySide one of course generates a Python class. Even if you use custom widgets (through \u201cPromote widget\u201d) instead of creating an <code data-no-translation=\"\">#include \"ui\/mywidget.h\"<\/code> directive, it creates a Python <code data-no-translation=\"\">from ui.mywidget import MyWidget<\/code> statement!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-272069b elementor-widget elementor-widget-text-editor\" data-id=\"272069b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>A simple \u201cHello World\u201d-like example could look like this:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-026abf7 elementor-widget elementor-widget-elementor-syntax-highlighter\" data-id=\"026abf7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"elementor-syntax-highlighter.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre data-no-translation=\"\"><code class='language-solid' data-no-translation=\"\">#!\/bin\/env python\nfrom PySide6.QtGui import QFont\nfrom PySide6.QtWidgets import QApplication, QLabel\nimport sys\n\nif __name__ == &quot;__main__&quot;:\n    app = QApplication(sys.argv)\n    app.setApplicationDisplayName(&quot;Hello, World&quot;)\n\n    label = QLabel(&quot;Hello from PySide!&quot;)\n    label.setFont(QFont(&quot;Noto Sans&quot;, 40))\n    label.show()\n\n    app.exec() <\/code><\/pre><script>\nif (!document.getElementById('syntaxed-prism')) {\n\tvar my_awesome_script = document.createElement('script');\n\tmy_awesome_script.setAttribute('src','https:\/\/www.basyskom.de\/wp-content\/plugins\/syntax-highlighter-for-elementor\/assets\/prism2.js');\n\tmy_awesome_script.setAttribute('id','syntaxed-prism');\n\tdocument.body.appendChild(my_awesome_script);\n} else {\n\twindow.Prism && Prism.highlightAll();\n}\n<\/script>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8db1580 elementor-widget elementor-widget-heading\" data-id=\"8db1580\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Qt Creator and Python?<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b3c9b8e elementor-widget elementor-widget-text-editor\" data-id=\"b3c9b8e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tQt Creator also has good support for Qt for Python. Since there\u2019s no QMake or CMake file to list your project\u2019s contents, you can instead create a <code data-no-translation=\"\">.pyproject<\/code> JSON file listing all the relevant files. Conveniently, Qt Creator then also executes the UI compiler and other relevant tools automatically when launching your application. Rather than assigning a compiler and linker to your kit, you manage a Python virtual environment, so every project can have its own clean set of dependencies.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eb426c8 elementor-widget elementor-widget-text-editor\" data-id=\"eb426c8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tThanks to Qt Creator\u2019s LSP integration, writing Python is super easy, it just uses <code data-no-translation=\"\">pylsp<\/code> to get autocompletion and warnings as you type. Even if you assign an object somewhere and pass it around five times, it still keeps track of what type it must have been and makes helpful suggestions.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a054f12 elementor-widget elementor-widget-text-editor\" data-id=\"a054f12\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tOverall the bindings are fantastic. It\u2019s great that I can think my Qt code through in C++ and then merely write it down in Python syntax. I haven\u2019t encountered a single thing that I could do in C++ that I couldn\u2019t implement using the Python bindings: <code data-no-translation=\"\">QAbstractItemModel<\/code>, <code data-no-translation=\"\">QIconEngine<\/code>, your own <code data-no-translation=\"\">QStyledItemDelegate<\/code>, heck, even a proper <code data-no-translation=\"\">QStyle<\/code>, it\u2019s all possible. The only minor issue I encountered was that type hints don\u2019t participate in method resolution. Unless you use something like <code data-no-translation=\"\">plum-dispatch<\/code> it\u2019s not possible to re-implement only a specific method overload. For example <code data-no-translation=\"\">QStyle::polish<\/code> can take either a <code data-no-translation=\"\">QWidget<\/code>, a <code data-no-translation=\"\">QApplication<\/code>, or a <code data-no-translation=\"\">QPalette<\/code>. A <code data-no-translation=\"\">def polish<\/code> will usually be called in all three cases.\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ec81529 elementor-widget elementor-widget-text-editor\" data-id=\"ec81529\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tThe documentation could also be better, especially for the more exotic use cases (good luck trying to figure out how to do a <code data-no-translation=\"\">QMetaObject.invokeMethod<\/code> with <code data-no-translation=\"\">qArg<\/code> from Python), often it\u2019s just haphazardly auto-translated from C++. Nevertheless, there\u2019s a plethora of example code in Qt\u2019s pyside\/examples Git repository to look at.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-895ff13 elementor-widget elementor-widget-heading\" data-id=\"895ff13\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">But Why?<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0f2fc15 elementor-widget elementor-widget-text-editor\" data-id=\"0f2fc15\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tNow that I have convinced you to give PySide6 a try, the obvious question would be: why bother? First of all, Python is very popular in data science and machine learning. If you already have scripts to collect data and analyze it, why not pour it into a beautiful user interface written in Qt without having to learn C++ first?\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-30427b3 elementor-widget elementor-widget-text-editor\" data-id=\"30427b3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tSomething quite neat is that every Python file could have a <code data-no-translation=\"\">__main__<\/code> entry point. If you place a small QApplication stub with the most basic backend objects required, you can easily run and test individual components detached from the main application. For instance, a dialog or panel that\u2019s like ten clicks away from the main window can just be shown and worked on directly. This encourages better modularization and to integrate components only once they\u2019ve reached a certain level of maturity.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9ca8960 elementor-widget elementor-widget-text-editor\" data-id=\"9ca8960\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tMoreover, Python has a huge ecosystem of 3rd party libraries. Just use <code data-no-translation=\"\">SQLAlchemy<\/code> instad of Qt SQL if that\u2019s what you\u2019re familiar with. Need to parse some YAML files? No problem! Why not take the easy route and use the <code data-no-translation=\"\">matplotlib<\/code> visualization code you have already written and just dump the result into a <code data-no-translation=\"\">QWidget<\/code>? On the other hand, if you rather prefer more Qt-like add-ons, the KDE Frameworks, a set of open-source libraries for Qt, are getting Python bindings as we speak.\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5701485 elementor-widget elementor-widget-heading\" data-id=\"5701485\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Further reading<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f5a3cff elementor-widget elementor-widget-text-editor\" data-id=\"f5a3cff\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul>\n<li>Qt for Python: Getting Started <a class=\"external-link\" href=\"https:\/\/doc.qt.io\/qtforpython-6\/gettingstarted.html\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/doc.qt.io\/qtforpython-6\/gettingstarted.html<\/a><\/li>\n<li>Python with Kirigami: <a class=\"external-link\" href=\"https:\/\/develop.kde.org\/docs\/getting-started\/python\/\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/develop.kde.org\/docs\/getting-started\/python\/<\/a><\/li>\n<\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In this article, we\u2019re going to have a look at Qt for Python, how it integrates with Qt Creator, and why you might want to consider using it, too.<\/p>","protected":false},"author":23,"featured_media":4011,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1,2,846,8],"tags":[805,804,15],"class_list":["post-11678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allgemein","category-blog","category-python","category-qt","tag-pyside","tag-python","tag-qt"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts\/11678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/comments?post=11678"}],"version-history":[{"count":14,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts\/11678\/revisions"}],"predecessor-version":[{"id":11970,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts\/11678\/revisions\/11970"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/media\/4011"}],"wp:attachment":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/media?parent=11678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/categories?post=11678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/tags?post=11678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}