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

Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in python
Sarfaraz Ghanta
 
Radial Basis Function
Radial Basis FunctionRadial Basis Function
Radial Basis Function
Madhawa Gunasekara
 
In-Depth Model/View with QML
In-Depth Model/View with QMLIn-Depth Model/View with QML
In-Depth Model/View with QML
ICS
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
Sumit Raj
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
Damian T. Gordon
 
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in Python
Microsoft
 
File handling in Python
File handling in PythonFile handling in Python
Beautiful soup
Beautiful soupBeautiful soup
Beautiful soup
mustafa sarac
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking framework
Phat VU
 
[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기
[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기
[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기
XpressEngine
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
Eueung Mulyana
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
Kevlin Henney
 
Matrix operations in practice using python
Matrix operations in practice using pythonMatrix operations in practice using python
Matrix operations in practice using python
Sina Torfi
 
Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
Prognoz Technologies Pvt. Ltd.
 
PYthon
PYthonPYthon
Python basics
Python basicsPython basics
Python basics
Jyoti shukla
 
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime modulePython Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
P3 InfoTech Solutions Pvt. Ltd.
 
PyQt: rapid application development
PyQt: rapid application developmentPyQt: rapid application development
PyQt: rapid application development
Develer S.r.l.
 

What's hot (20)

Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in python
 
Radial Basis Function
Radial Basis FunctionRadial Basis Function
Radial Basis Function
 
In-Depth Model/View with QML
In-Depth Model/View with QMLIn-Depth Model/View with QML
In-Depth Model/View with QML
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in Python
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Beautiful soup
Beautiful soupBeautiful soup
Beautiful soup
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking framework
 
[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기
[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기
[XECon2016] A-4 조정현 GitHub + Jenkins + Docker로 자동배포 시스템 구축하기
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 
Matrix operations in practice using python
Matrix operations in practice using pythonMatrix operations in practice using python
Matrix operations in practice using python
 
Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
 
PYthon
PYthonPYthon
PYthon
 
Python basics
Python basicsPython basics
Python basics
 
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime modulePython Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
 
PyQt: rapid application development
PyQt: rapid application developmentPyQt: rapid application development
PyQt: rapid application development
 

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 5 - C++ and Widgets
Qt 5 - C++ and WidgetsQt 5 - C++ and Widgets
Qt 5 - C++ and Widgets
Juha Peltomäki
 
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
 
PyQt.pptx
PyQt.pptxPyQt.pptx
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 2011
Johan 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_latest
Srikanth Pilli
 

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 5 - C++ and Widgets
Qt 5 - C++ and WidgetsQt 5 - C++ and Widgets
Qt 5 - C++ and Widgets
 
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
 

More from ICS

Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
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
 

More from ICS (20)

Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
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
 

Recently uploaded

在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
AnkitaPandya11
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 

Recently uploaded (20)

在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 

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