SlideShare a Scribd company logo
Integrated Computer Solutions Inc. www.ics.com
Qt for Python
March 21, 2019
Copyright 2019, Integrated Computers Solutions, Inc.
This work may not be reproduced in whole or in part without the express written consent of Integrated Computer Solutions, Inc.
1
Integrated Computer Solutions Inc. www.ics.com
What is Qt for Python?
• Also known as PySide 2
• Qt for Python are the Python v2 and v3 bindings for Qt
• Qt for Python gives the Python programmer access to the full Qt API
• API is the same from C++
• Qt for Python is available under the LGPL v3 and the Qt Commercial License.
• Owned and distributed by The Qt Company
2
Integrated Computer Solutions Inc. www.ics.com
Other Features
• The APIs are almost identical to C++, so experienced Qt users can quickly get
up to speed and leverage their Qt knowledge.
• You can continue to use Qt Designer .ui files and resources.
• If you are porting a C++ application, you can mostly one for one port much of
the code.
• Run time errors are usually straightforward.
• A developer can be very productive due to not needing a compile/build cycle.
https://www.ics.com/blog/we-ported-qt-app-c-python-heres-what-happened
3
Integrated Computer Solutions Inc. www.ics.com
Confusion with PyQt
• PyQt is another product that provides Python bindings to Qt (and is mostly
compatible with PySide)
• PyQt is dual licensed on all supported platforms under the GNU GPL v3 and
the Riverbank Commercial License (LGPL not available)
• PyQt is owned and distributed by Riverbank
• Differences between Python for Qt and PyQt are discussed here:
https://machinekoder.com/pyqt-vs-qt-for-python-pyside2-pyside/
4
Integrated Computer Solutions Inc. www.ics.com
What is Qt?
• Cross-Platform C++ class library
• Encompasses some 1,500 C++ classes
• Started as a Graphics User Interface (GUI) toolkit
• Is much more today: Threads, XML/JSON parsing, Regular Expressions, Sockets, HTML parsing
• Development for Desktop and Embedded Devices
• Qt is available under commercial and open source licenses
• In addition to class libraries, Qt framework contains several tools, like Qt Creator (IDE), Qt Designer,
qmake, Qt Linguist
• Owned and distributed by The Qt Company
5
Integrated Computer Solutions Inc. www.ics.com
How to Install
• After you have installed Python,
• Python install is in your path
• Other ways to install (including building):
https://wiki.qt.io/Qt_for_Python/GettingStarted
pip install PySide2
6
Integrated Computer Solutions Inc. www.ics.com
“Hello World” in Pyside 2 — Widget-Based
#!/usr/bin/env python3
import sys
from PySide2.QtWidgets import QApplication, QPushButton
if __name__ == '__main__':
app = QApplication(sys.argv)
button = QPushButton(None) #Creates a widget
button.setText("Hello world")
button.show()
sys.exit(app.exec_()) #Starts the event loop
Program consists of:
• py_qtsimple.py
7
Integrated Computer Solutions Inc. www.ics.com
A First Example with Widgets
class customWidget(QtWidgets.QWidget):
def __init__(self):
QtWidgets.QWidget.__init__(self)
self.setWindowTitle(self.tr("My First Example"))
self.label = QtWidgets.QLabel("Note:", self)
self.edit = QtWidgets.QTextEdit(self)
self.clear = QtWidgets.QPushButton("Clear", self)
self.save = QtWidgets.QPushButton("Save", self)
# Widget layout
self.outer = QtWidgets.QVBoxLayout()
self.outer.addWidget(self.label)
self.outer.addWidget(self.edit)
self.inner = QtWidgets.QHBoxLayout()
self.inner.addWidget(self.clear)
self.inner.addWidget(self.save)
self.setLayout(self.outer)
# Nesting layouts
self.outer.addLayout(self.inner)
8
Integrated Computer Solutions Inc. www.ics.com
“Hello World” in Pyside2 — Qt Quick-Based
9
#!/usr/bin/env python3
import sys
from PySide2.QtCore import QUrl
from PySide2.QtQuick import QQuickView
from PySide2.QtWidgets import QApplication
if __name__ == '__main__':
app = QApplication(sys.argv)
view = QQuickView()
view.setSource(QUrl('main.qml'))
view.show() # window created in QML
sys.exit(app.exec_())
Program consists of
• HelloWorldQML.py – creation and startup of the QML engine (with executable
permissions)
• main.qml – application code
Integrated Computer Solutions Inc. www.ics.com
Qt Creator IDE
● Advanced C++, QML and Python code
editor
● 100% open source, written in Qt 5
● Integrated GUI layout and form designer
● Rapid code
navigation tools
● Supports multiple
Platforms
● Downloadable here
https://www.qt.io/offline-installers
10
Integrated Computer Solutions Inc. www.ics.com
Qt Components
List of available Qt modules are here:
https://doc.qt.io/qtforpython/?hsCtaTracking=fab9e910-0b90-4caa-b6d0-e202692b6f13%7Cb9e0be8d-1
d85-4644-aaa2-41de4e6d37e3#qt-modules
11
Integrated Computer Solutions Inc. www.ics.com
Use of Qt Designer
12
import sys
from PySide2 import QtWidgets
from form import Ui_Form
class MyForm(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myapp = MyForm()
myapp.ui.pushButton.clicked.connect(app.quit)
myapp.show()
sys.exit(app.exec_())
• Requires the compilation of a form:
pyside2-uic.exe form.ui > form.py
Integrated Computer Solutions Inc. www.ics.com
Use of Qt Designer with UILoader
from PySide2.QtUiTools import QUiLoader
from PySide2 import QtWidgets
from PySide2.QtCore import QFile
class MyForm(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
file = QFile("form.ui")
file.open(QFile.ReadOnly)
self.loader = QUiLoader()
self.myWidget = self.loader.load(file, self)
file.close()
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.myWidget)
self.setLayout(layout)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
13
Integrated Computer Solutions Inc. www.ics.com
Signals and Slots
from PySide2.QtCore import SIGNAL, QObject
# define a new slot that receives a string and has
# 'saySomeWords' as its name
@Slot(str)
def say_some_words(words):
print(words)
class Communicate(QObject):
# create a new signal on the fly and name it 'speak'
speak = Signal(str)
someone = Communicate()
# connect signal and slot
someone.speak.connect(say_some_words)
# emit 'speak' signal
someone.speak.emit("Hello everybody!")
See https://wiki.qt.io/Qt_for_Python_Signals_and_Slots
14
Integrated Computer Solutions Inc. www.ics.com
Reimplementing Events
from PySide2.QtWidgets import QWidget
from PySide2.QtCore import Qt, Signal
class MainWidget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.resize(400, 300)
self.setWindowTitle("Widget Event Example")
self.setFocusPolicy(Qt.StrongFocus)
def mousePressEvent(self, event):
if self.m_logAll:
self.notifyEvent['QString', 'QEvent'].emit("mousePressEvent", event)
super(MainWidget, self).mousePressEvent(event)
15
Integrated Computer Solutions Inc. www.ics.com
The Property System
from PySide2.QtCore import QObject, Signal, Property
class Person(QObject):
def __init__(self, name):
QObject.__init__(self)
self._person_name = name
def _name(self):
return self._person_name
@Signal
def name_changed(self):
pass
name = Property(str, _name, notify=name_changed)
• Useful in QML
16
Integrated Computer Solutions Inc. www.ics.com
Some Notes to Keep in Mind
• No QString, use Python string (str)
• The Qt container classes are not available, use the ones provided by Python
• Some Qt method names Qt names have had an underscore appended to
resolve this conflict (i.e. QTextStream methods bin_(), hex_(), oct_() and
QDialog exec_())
• No QVariants! Any Qt function expecting or returning a QVariant can receive
or return any Python object
17
Integrated Computer Solutions Inc. www.ics.com
Business Logic/UI Paradigm
18
Business Logic
Python
UI in Python
(Widgets)
Or QML
Integrated Computer Solutions Inc. www.ics.com
When to Use Non-GUI PySide 2
• Dealing with not blocking your GUI (QProcess, networking, QSerial vs.
PySerial, etc.)
• QSqlDatabase because you want to show it in a QTableView
• Better integration with Qt in general (e.g. QThread)
19
Integrated Computer Solutions Inc. www.ics.com
Where to Get Help
• https://qmlbook.github.io/ch18-python/python.html
• PySide2 Mailing List https://lists.qt-project.org/mailman/listinfo/pyside
• AppDataLocalProgramsPythonPython37-32Libsite-packagesPySide2
examples
• Tutorial: https://build-system.fman.io/python-qt-tutorial
20
Integrated Computer Solutions Inc. www.ics.com
Programming with Qt for Python Training Course
● New 5-day hands-on introduction to developing desktop applications using
the official set of Python bindings covering:
● GUI programming
● GraphicsView
● Model/View
● Challenges inherent to mixing the Qt API with Python
● May 13 - 17 - Waltham, MA
● June 24 - 28, Sunnyvale, CA
● https://www.ics.com/learning/training/programming-qt-python
21

More Related Content

What's hot

The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
UI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QMLUI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QML
Emertxe Information Technologies Pvt Ltd
 
Python programming introduction
Python programming introductionPython programming introduction
Python programming introduction
Siddique Ibrahim
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
QA TrainingHub
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
primeteacher32
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part I
ICS
 
PyQt: rapid application development
PyQt: rapid application developmentPyQt: rapid application development
PyQt: rapid application development
Develer S.r.l.
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part II
ICS
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
Andreas Jakl
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
Arun Prasad
 
Introduction to QML
Introduction to QMLIntroduction to QML
Introduction to QML
Alan Uthoff
 
Python basic
Python basicPython basic
Python basic
radhikaadroja
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
ICS
 
Windows Xp Optimization
Windows Xp OptimizationWindows Xp Optimization
Windows Xp Optimization
Shan Sachwani
 
GoLang Introduction
GoLang IntroductionGoLang Introduction
GoLang Introduction
Spandana Govindgari
 
Introduction to Android Window System
Introduction to Android Window SystemIntroduction to Android Window System
Introduction to Android Window System
National Cheng Kung University
 

What's hot (20)

The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
UI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QMLUI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QML
 
Python programming introduction
Python programming introductionPython programming introduction
Python programming introduction
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part I
 
PyQt: rapid application development
PyQt: rapid application developmentPyQt: rapid application development
PyQt: rapid application development
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part II
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Introduction to QML
Introduction to QMLIntroduction to QML
Introduction to QML
 
Python basic
Python basicPython basic
Python basic
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 
Windows Xp Optimization
Windows Xp OptimizationWindows Xp Optimization
Windows Xp Optimization
 
GoLang Introduction
GoLang IntroductionGoLang Introduction
GoLang Introduction
 
Introduction to Android Window System
Introduction to Android Window SystemIntroduction to Android Window System
Introduction to Android Window System
 

Similar to Qt for Python

So I downloaded Qt, Now What?
So I downloaded Qt, Now What?So I downloaded Qt, Now What?
So I downloaded Qt, Now What?
ICS
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?
Janel Heilbrunn
 
Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017
Johan Thelin
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
ICS
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
Janel Heilbrunn
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
ICS
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing more
ICS
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to Qt
Janel Heilbrunn
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to Qt
ICS
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Prabindh Sundareson
 
PyQt Application Development On Maemo
PyQt Application Development On MaemoPyQt Application Development On Maemo
PyQt Application Development On Maemo
achipa
 
IBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt IntegrationIBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt Integration
gjuljo
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Johan Thelin
 
Treinamento Qt básico - aula I
Treinamento Qt básico - aula ITreinamento Qt básico - aula I
Treinamento Qt básico - aula I
Marcelo Barros de Almeida
 
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
Qualcomm Developer Network
 
Kivy report
Kivy reportKivy report
Kivy report
shobhit bhatnagar
 
Contribuire al Qt Project
Contribuire al Qt ProjectContribuire al Qt Project
Contribuire al Qt Project
QT-day
 
Srikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth Pilli
 
Software Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business LogicSoftware Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business Logic
ICS
 

Similar to Qt for Python (20)

So I downloaded Qt, Now What?
So I downloaded Qt, Now What?So I downloaded Qt, Now What?
So I downloaded Qt, Now What?
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?
 
Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing more
 
PyQt.pptx
PyQt.pptxPyQt.pptx
PyQt.pptx
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to Qt
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to Qt
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
 
PyQt Application Development On Maemo
PyQt Application Development On MaemoPyQt Application Development On Maemo
PyQt Application Development On Maemo
 
IBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt IntegrationIBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt Integration
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
 
Treinamento Qt básico - aula I
Treinamento Qt básico - aula ITreinamento Qt básico - aula I
Treinamento Qt básico - aula I
 
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
 
Kivy report
Kivy reportKivy report
Kivy report
 
Contribuire al Qt Project
Contribuire al Qt ProjectContribuire al Qt Project
Contribuire al Qt Project
 
Srikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latest
 
Software Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business LogicSoftware Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business Logic
 

More from ICS

A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
ICS
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ICS
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
ICS
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
ICS
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
ICS
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
ICS
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
ICS
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdf
ICS
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdf
ICS
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up
ICS
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdf
ICS
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
ICS
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management Solution
ICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
ICS
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with Azure
ICS
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt Users
ICS
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
ICS
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer Framework
ICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
ICS
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case Study
ICS
 

More from ICS (20)

A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdf
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdf
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdf
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management Solution
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with Azure
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt Users
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer Framework
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case Study
 

Recently uploaded

De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 

Recently uploaded (20)

De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 

Qt for Python

  • 1. Integrated Computer Solutions Inc. www.ics.com Qt for Python March 21, 2019 Copyright 2019, Integrated Computers Solutions, Inc. This work may not be reproduced in whole or in part without the express written consent of Integrated Computer Solutions, Inc. 1
  • 2. Integrated Computer Solutions Inc. www.ics.com What is Qt for Python? • Also known as PySide 2 • Qt for Python are the Python v2 and v3 bindings for Qt • Qt for Python gives the Python programmer access to the full Qt API • API is the same from C++ • Qt for Python is available under the LGPL v3 and the Qt Commercial License. • Owned and distributed by The Qt Company 2
  • 3. Integrated Computer Solutions Inc. www.ics.com Other Features • The APIs are almost identical to C++, so experienced Qt users can quickly get up to speed and leverage their Qt knowledge. • You can continue to use Qt Designer .ui files and resources. • If you are porting a C++ application, you can mostly one for one port much of the code. • Run time errors are usually straightforward. • A developer can be very productive due to not needing a compile/build cycle. https://www.ics.com/blog/we-ported-qt-app-c-python-heres-what-happened 3
  • 4. Integrated Computer Solutions Inc. www.ics.com Confusion with PyQt • PyQt is another product that provides Python bindings to Qt (and is mostly compatible with PySide) • PyQt is dual licensed on all supported platforms under the GNU GPL v3 and the Riverbank Commercial License (LGPL not available) • PyQt is owned and distributed by Riverbank • Differences between Python for Qt and PyQt are discussed here: https://machinekoder.com/pyqt-vs-qt-for-python-pyside2-pyside/ 4
  • 5. Integrated Computer Solutions Inc. www.ics.com What is Qt? • Cross-Platform C++ class library • Encompasses some 1,500 C++ classes • Started as a Graphics User Interface (GUI) toolkit • Is much more today: Threads, XML/JSON parsing, Regular Expressions, Sockets, HTML parsing • Development for Desktop and Embedded Devices • Qt is available under commercial and open source licenses • In addition to class libraries, Qt framework contains several tools, like Qt Creator (IDE), Qt Designer, qmake, Qt Linguist • Owned and distributed by The Qt Company 5
  • 6. Integrated Computer Solutions Inc. www.ics.com How to Install • After you have installed Python, • Python install is in your path • Other ways to install (including building): https://wiki.qt.io/Qt_for_Python/GettingStarted pip install PySide2 6
  • 7. Integrated Computer Solutions Inc. www.ics.com “Hello World” in Pyside 2 — Widget-Based #!/usr/bin/env python3 import sys from PySide2.QtWidgets import QApplication, QPushButton if __name__ == '__main__': app = QApplication(sys.argv) button = QPushButton(None) #Creates a widget button.setText("Hello world") button.show() sys.exit(app.exec_()) #Starts the event loop Program consists of: • py_qtsimple.py 7
  • 8. Integrated Computer Solutions Inc. www.ics.com A First Example with Widgets class customWidget(QtWidgets.QWidget): def __init__(self): QtWidgets.QWidget.__init__(self) self.setWindowTitle(self.tr("My First Example")) self.label = QtWidgets.QLabel("Note:", self) self.edit = QtWidgets.QTextEdit(self) self.clear = QtWidgets.QPushButton("Clear", self) self.save = QtWidgets.QPushButton("Save", self) # Widget layout self.outer = QtWidgets.QVBoxLayout() self.outer.addWidget(self.label) self.outer.addWidget(self.edit) self.inner = QtWidgets.QHBoxLayout() self.inner.addWidget(self.clear) self.inner.addWidget(self.save) self.setLayout(self.outer) # Nesting layouts self.outer.addLayout(self.inner) 8
  • 9. Integrated Computer Solutions Inc. www.ics.com “Hello World” in Pyside2 — Qt Quick-Based 9 #!/usr/bin/env python3 import sys from PySide2.QtCore import QUrl from PySide2.QtQuick import QQuickView from PySide2.QtWidgets import QApplication if __name__ == '__main__': app = QApplication(sys.argv) view = QQuickView() view.setSource(QUrl('main.qml')) view.show() # window created in QML sys.exit(app.exec_()) Program consists of • HelloWorldQML.py – creation and startup of the QML engine (with executable permissions) • main.qml – application code
  • 10. Integrated Computer Solutions Inc. www.ics.com Qt Creator IDE ● Advanced C++, QML and Python code editor ● 100% open source, written in Qt 5 ● Integrated GUI layout and form designer ● Rapid code navigation tools ● Supports multiple Platforms ● Downloadable here https://www.qt.io/offline-installers 10
  • 11. Integrated Computer Solutions Inc. www.ics.com Qt Components List of available Qt modules are here: https://doc.qt.io/qtforpython/?hsCtaTracking=fab9e910-0b90-4caa-b6d0-e202692b6f13%7Cb9e0be8d-1 d85-4644-aaa2-41de4e6d37e3#qt-modules 11
  • 12. Integrated Computer Solutions Inc. www.ics.com Use of Qt Designer 12 import sys from PySide2 import QtWidgets from form import Ui_Form class MyForm(QtWidgets.QWidget): def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.ui = Ui_Form() self.ui.setupUi(self) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) myapp = MyForm() myapp.ui.pushButton.clicked.connect(app.quit) myapp.show() sys.exit(app.exec_()) • Requires the compilation of a form: pyside2-uic.exe form.ui > form.py
  • 13. Integrated Computer Solutions Inc. www.ics.com Use of Qt Designer with UILoader from PySide2.QtUiTools import QUiLoader from PySide2 import QtWidgets from PySide2.QtCore import QFile class MyForm(QtWidgets.QWidget): def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) file = QFile("form.ui") file.open(QFile.ReadOnly) self.loader = QUiLoader() self.myWidget = self.loader.load(file, self) file.close() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.myWidget) self.setLayout(layout) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) myapp = MyForm() myapp.show() sys.exit(app.exec_()) 13
  • 14. Integrated Computer Solutions Inc. www.ics.com Signals and Slots from PySide2.QtCore import SIGNAL, QObject # define a new slot that receives a string and has # 'saySomeWords' as its name @Slot(str) def say_some_words(words): print(words) class Communicate(QObject): # create a new signal on the fly and name it 'speak' speak = Signal(str) someone = Communicate() # connect signal and slot someone.speak.connect(say_some_words) # emit 'speak' signal someone.speak.emit("Hello everybody!") See https://wiki.qt.io/Qt_for_Python_Signals_and_Slots 14
  • 15. Integrated Computer Solutions Inc. www.ics.com Reimplementing Events from PySide2.QtWidgets import QWidget from PySide2.QtCore import Qt, Signal class MainWidget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.resize(400, 300) self.setWindowTitle("Widget Event Example") self.setFocusPolicy(Qt.StrongFocus) def mousePressEvent(self, event): if self.m_logAll: self.notifyEvent['QString', 'QEvent'].emit("mousePressEvent", event) super(MainWidget, self).mousePressEvent(event) 15
  • 16. Integrated Computer Solutions Inc. www.ics.com The Property System from PySide2.QtCore import QObject, Signal, Property class Person(QObject): def __init__(self, name): QObject.__init__(self) self._person_name = name def _name(self): return self._person_name @Signal def name_changed(self): pass name = Property(str, _name, notify=name_changed) • Useful in QML 16
  • 17. Integrated Computer Solutions Inc. www.ics.com Some Notes to Keep in Mind • No QString, use Python string (str) • The Qt container classes are not available, use the ones provided by Python • Some Qt method names Qt names have had an underscore appended to resolve this conflict (i.e. QTextStream methods bin_(), hex_(), oct_() and QDialog exec_()) • No QVariants! Any Qt function expecting or returning a QVariant can receive or return any Python object 17
  • 18. Integrated Computer Solutions Inc. www.ics.com Business Logic/UI Paradigm 18 Business Logic Python UI in Python (Widgets) Or QML
  • 19. Integrated Computer Solutions Inc. www.ics.com When to Use Non-GUI PySide 2 • Dealing with not blocking your GUI (QProcess, networking, QSerial vs. PySerial, etc.) • QSqlDatabase because you want to show it in a QTableView • Better integration with Qt in general (e.g. QThread) 19
  • 20. Integrated Computer Solutions Inc. www.ics.com Where to Get Help • https://qmlbook.github.io/ch18-python/python.html • PySide2 Mailing List https://lists.qt-project.org/mailman/listinfo/pyside • AppDataLocalProgramsPythonPython37-32Libsite-packagesPySide2 examples • Tutorial: https://build-system.fman.io/python-qt-tutorial 20
  • 21. Integrated Computer Solutions Inc. www.ics.com Programming with Qt for Python Training Course ● New 5-day hands-on introduction to developing desktop applications using the official set of Python bindings covering: ● GUI programming ● GraphicsView ● Model/View ● Challenges inherent to mixing the Qt API with Python ● May 13 - 17 - Waltham, MA ● June 24 - 28, Sunnyvale, CA ● https://www.ics.com/learning/training/programming-qt-python 21