aboutsummaryrefslogtreecommitdiffstats
path: root/examples/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tutorial')
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t1.py48
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t10.py78
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t11.py86
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t12.py90
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t13.py109
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t14.py123
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t2.py48
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t3.py50
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t4.py54
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t5.py60
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t6.py68
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t7.py70
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t8.py74
-rw-r--r--[-rwxr-xr-x]examples/tutorial/t9.py74
14 files changed, 827 insertions, 205 deletions
diff --git a/examples/tutorial/t1.py b/examples/tutorial/t1.py
index 26b00c2..b3251db 100755..100644
--- a/examples/tutorial/t1.py
+++ b/examples/tutorial/t1.py
@@ -1,15 +1,55 @@
#!/usr/bin/env python
-# PyQt tutorial 1
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 1
import sys
-from PySide2 import QtGui
+from PySide2 import QtWidgets
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
-hello = QtGui.QPushButton("Hello world!")
+hello = QtWidgets.QPushButton("Hello world!")
hello.resize(100, 30)
hello.show()
diff --git a/examples/tutorial/t10.py b/examples/tutorial/t10.py
index 86fa1ee..081190c 100755..100644
--- a/examples/tutorial/t10.py
+++ b/examples/tutorial/t10.py
@@ -1,18 +1,59 @@
#!/usr/bin/env python
-# PyQt tutorial 10
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 10
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- lcd = QtGui.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
@@ -21,7 +62,7 @@ class LCDRange(QtGui.QWidget):
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
self.setLayout(layout)
@@ -31,6 +72,7 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
@@ -44,9 +86,11 @@ class LCDRange(QtGui.QWidget):
self.slider.setRange(minValue, maxValue)
-class CannonField(QtGui.QWidget):
+class CannonField(QtWidgets.QWidget):
+ angleChanged = QtCore.Signal(int)
+ forceChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.currentAngle = 45
self.currentForce = 0
@@ -56,6 +100,7 @@ class CannonField(QtGui.QWidget):
def angle(self):
return self.currentAngle
+ @QtCore.Slot(int)
def setAngle(self, angle):
if angle < 5:
angle = 5
@@ -70,6 +115,7 @@ class CannonField(QtGui.QWidget):
def force(self):
return self.currentForce
+ @QtCore.Slot(int)
def setForce(self, force):
if force < 0:
force = 0
@@ -95,15 +141,15 @@ class CannonField(QtGui.QWidget):
return result
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("&Quit")
+ quit = QtWidgets.QPushButton("&Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
angle = LCDRange()
angle.setRange(5, 70)
@@ -123,11 +169,11 @@ class MyWidget(QtGui.QWidget):
self.connect(cannonField, QtCore.SIGNAL("forceChanged(int)"),
force.setValue)
- leftLayout = QtGui.QVBoxLayout()
+ leftLayout = QtWidgets.QVBoxLayout()
leftLayout.addWidget(angle)
leftLayout.addWidget(force)
- gridLayout = QtGui.QGridLayout()
+ gridLayout = QtWidgets.QGridLayout()
gridLayout.addWidget(quit, 0, 0)
gridLayout.addLayout(leftLayout, 1, 0)
gridLayout.addWidget(cannonField, 1, 1, 2, 1)
@@ -139,7 +185,7 @@ class MyWidget(QtGui.QWidget):
angle.setFocus()
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.setGeometry(100, 100, 500, 355)
widget.show()
diff --git a/examples/tutorial/t11.py b/examples/tutorial/t11.py
index 9b3da8a..070782b 100755..100644
--- a/examples/tutorial/t11.py
+++ b/examples/tutorial/t11.py
@@ -1,19 +1,60 @@
#!/usr/bin/env python
-# PyQt tutorial 11
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 11
import sys
import math
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- lcd = QtGui.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
@@ -22,7 +63,7 @@ class LCDRange(QtGui.QWidget):
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
self.setLayout(layout)
@@ -32,6 +73,7 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
@@ -45,9 +87,11 @@ class LCDRange(QtGui.QWidget):
self.slider.setRange(minValue, maxValue)
-class CannonField(QtGui.QWidget):
+class CannonField(QtWidgets.QWidget):
+ angleChanged = QtCore.Signal(int)
+ forceChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.currentAngle = 45
self.currentForce = 0
@@ -63,6 +107,7 @@ class CannonField(QtGui.QWidget):
def angle(self):
return self.currentAngle
+ @QtCore.Slot(int)
def setAngle(self, angle):
if angle < 5:
angle = 5
@@ -77,6 +122,7 @@ class CannonField(QtGui.QWidget):
def force(self):
return self.currentForce
+ @QtCore.Slot(int)
def setForce(self, force):
if force < 0:
force = 0
@@ -85,6 +131,7 @@ class CannonField(QtGui.QWidget):
self.currentForce = force;
self.emit(QtCore.SIGNAL("forceChanged(int)"), self.currentForce)
+ @QtCore.Slot()
def shoot(self):
if self.autoShootTimer.isActive():
return
@@ -93,6 +140,7 @@ class CannonField(QtGui.QWidget):
self.shootForce = self.currentForce
self.autoShootTimer.start(5)
+ @QtCore.Slot()
def moveShot(self):
region = QtGui.QRegion(self.shotRect())
self.timerCount += 1
@@ -151,19 +199,19 @@ class CannonField(QtGui.QWidget):
y = y0 + vely * time - 0.5 * gravity * time * time
result = QtCore.QRect(0, 0, 6, 6)
- result.moveCenter(QtCore.QPoint(QtCore.qRound(x), self.height() - 1 - QtCore.qRound(y)))
+ result.moveCenter(QtCore.QPoint(round(x), self.height() - 1 - round(y)))
return result
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("&Quit")
+ quit = QtWidgets.QPushButton("&Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
angle = LCDRange()
angle.setRange(5, 70)
@@ -183,20 +231,20 @@ class MyWidget(QtGui.QWidget):
self.connect(cannonField, QtCore.SIGNAL("forceChanged(int)"),
force.setValue)
- shoot = QtGui.QPushButton("&Shoot")
+ shoot = QtWidgets.QPushButton("&Shoot")
shoot.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(shoot, QtCore.SIGNAL("clicked()"), cannonField.shoot)
- topLayout = QtGui.QHBoxLayout()
+ topLayout = QtWidgets.QHBoxLayout()
topLayout.addWidget(shoot)
topLayout.addStretch(1)
- leftLayout = QtGui.QVBoxLayout()
+ leftLayout = QtWidgets.QVBoxLayout()
leftLayout.addWidget(angle)
leftLayout.addWidget(force)
- gridLayout = QtGui.QGridLayout()
+ gridLayout = QtWidgets.QGridLayout()
gridLayout.addWidget(quit, 0, 0)
gridLayout.addLayout(topLayout, 0, 1)
gridLayout.addLayout(leftLayout, 1, 0)
@@ -209,7 +257,7 @@ class MyWidget(QtGui.QWidget):
angle.setFocus()
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.setGeometry(100, 100, 500, 355)
widget.show()
diff --git a/examples/tutorial/t12.py b/examples/tutorial/t12.py
index 1be4b3b..6afd880 100755..100644
--- a/examples/tutorial/t12.py
+++ b/examples/tutorial/t12.py
@@ -1,21 +1,62 @@
#!/usr/bin/env python
-# PyQt tutorial 12
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 12
import sys
import math
import random
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, text=None, parent=None):
- if isinstance(text, QtGui.QWidget):
+ if isinstance(text, QtWidgets.QWidget):
parent = text
text = None
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.init()
@@ -23,11 +64,11 @@ class LCDRange(QtGui.QWidget):
self.setText(text)
def init(self):
- lcd = QtGui.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
- self.label = QtGui.QLabel()
+ self.label = QtWidgets.QLabel()
self.label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
@@ -35,7 +76,7 @@ class LCDRange(QtGui.QWidget):
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
layout.addWidget(self.label)
@@ -46,6 +87,7 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
@@ -65,9 +107,11 @@ class LCDRange(QtGui.QWidget):
self.label.setText(text)
-class CannonField(QtGui.QWidget):
+class CannonField(QtWidgets.QWidget):
+ angleChanged = QtCore.Signal(int)
+ forceChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.currentAngle = 45
self.currentForce = 0
@@ -85,6 +129,7 @@ class CannonField(QtGui.QWidget):
def angle(self):
return self.currentAngle
+ @QtCore.Slot(int)
def setAngle(self, angle):
if angle < 5:
angle = 5
@@ -99,6 +144,7 @@ class CannonField(QtGui.QWidget):
def force(self):
return self.currentForce
+ @QtCore.Slot(int)
def setForce(self, force):
if force < 0:
force = 0
@@ -107,6 +153,7 @@ class CannonField(QtGui.QWidget):
self.currentForce = force;
self.emit(QtCore.SIGNAL("forceChanged(int)"), self.currentForce)
+ @QtCore.Slot()
def shoot(self):
if self.autoShootTimer.isActive():
return
@@ -126,6 +173,7 @@ class CannonField(QtGui.QWidget):
self.target = QtCore.QPoint(200 + random.randint(0, 190 - 1), 10 + random.randint(0, 255 - 1))
self.update()
+ @QtCore.Slot()
def moveShot(self):
region = QtGui.QRegion(self.shotRect())
self.timerCount += 1
@@ -195,7 +243,7 @@ class CannonField(QtGui.QWidget):
y = y0 + vely * time - 0.5 * gravity * time * time
result = QtCore.QRect(0, 0, 6, 6)
- result.moveCenter(QtCore.QPoint(QtCore.qRound(x), self.height() - 1 - QtCore.qRound(y)))
+ result.moveCenter(QtCore.QPoint(round(x), self.height() - 1 - round(y)))
return result
def targetRect(self):
@@ -204,15 +252,15 @@ class CannonField(QtGui.QWidget):
return result
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("&Quit")
+ quit = QtWidgets.QPushButton("&Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
angle = LCDRange("ANGLE")
angle.setRange(5, 70)
@@ -232,20 +280,20 @@ class MyWidget(QtGui.QWidget):
self.connect(cannonField, QtCore.SIGNAL("forceChanged(int)"),
force.setValue)
- shoot = QtGui.QPushButton("&Shoot")
+ shoot = QtWidgets.QPushButton("&Shoot")
shoot.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(shoot, QtCore.SIGNAL("clicked()"), cannonField.shoot)
- topLayout = QtGui.QHBoxLayout()
+ topLayout = QtWidgets.QHBoxLayout()
topLayout.addWidget(shoot)
topLayout.addStretch(1)
- leftLayout = QtGui.QVBoxLayout()
+ leftLayout = QtWidgets.QVBoxLayout()
leftLayout.addWidget(angle)
leftLayout.addWidget(force)
- gridLayout = QtGui.QGridLayout()
+ gridLayout = QtWidgets.QGridLayout()
gridLayout.addWidget(quit, 0, 0)
gridLayout.addLayout(topLayout, 0, 1)
gridLayout.addLayout(leftLayout, 1, 0)
@@ -258,7 +306,7 @@ class MyWidget(QtGui.QWidget):
angle.setFocus()
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.setGeometry(100, 100, 500, 355)
widget.show()
diff --git a/examples/tutorial/t13.py b/examples/tutorial/t13.py
index 41829a4..34f2fe5 100755..100644
--- a/examples/tutorial/t13.py
+++ b/examples/tutorial/t13.py
@@ -1,21 +1,62 @@
#!/usr/bin/env python
-# PyQt tutorial 13
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 13
import sys
import math
import random
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, text=None, parent=None):
- if isinstance(text, QtGui.QWidget):
+ if isinstance(text, QtWidgets.QWidget):
parent = text
text = None
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.init()
@@ -23,20 +64,20 @@ class LCDRange(QtGui.QWidget):
self.setText(text)
def init(self):
- lcd = QtGui.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
- self.label = QtGui.QLabel()
+ self.label = QtWidgets.QLabel()
self.label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
- self.label.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
+ self.label.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
lcd, QtCore.SLOT("display(int)"))
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
layout.addWidget(self.label)
@@ -47,6 +88,7 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
@@ -66,9 +108,14 @@ class LCDRange(QtGui.QWidget):
self.label.setText(text)
-class CannonField(QtGui.QWidget):
+class CannonField(QtWidgets.QWidget):
+ angleChanged = QtCore.Signal(int)
+ forceChanged = QtCore.Signal(int)
+ hit = QtCore.Signal()
+ missed = QtCore.Signal()
+ canShoot = QtCore.Signal(bool)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.currentAngle = 45
self.currentForce = 0
@@ -87,6 +134,7 @@ class CannonField(QtGui.QWidget):
def angle(self):
return self.currentAngle
+ @QtCore.Slot(int)
def setAngle(self, angle):
if angle < 5:
angle = 5
@@ -101,6 +149,7 @@ class CannonField(QtGui.QWidget):
def force(self):
return self.currentForce
+ @QtCore.Slot(int)
def setForce(self, force):
if force < 0:
force = 0
@@ -109,6 +158,7 @@ class CannonField(QtGui.QWidget):
self.currentForce = force;
self.emit(QtCore.SIGNAL("forceChanged(int)"), self.currentForce)
+ @QtCore.Slot()
def shoot(self):
if self.isShooting():
return
@@ -144,6 +194,7 @@ class CannonField(QtGui.QWidget):
self.update()
self.emit(QtCore.SIGNAL("canShoot(bool)"), True)
+ @QtCore.Slot()
def moveShot(self):
region = QtGui.QRegion(self.shotRect())
self.timerCount += 1
@@ -220,7 +271,7 @@ class CannonField(QtGui.QWidget):
y = y0 + vely * time - 0.5 * gravity * time * time
result = QtCore.QRect(0, 0, 6, 6)
- result.moveCenter(QtCore.QPoint(QtCore.qRound(x), self.height() - 1 - QtCore.qRound(y)))
+ result.moveCenter(QtCore.QPoint(round(x), self.height() - 1 - round(y)))
return result
def targetRect(self):
@@ -235,15 +286,15 @@ class CannonField(QtGui.QWidget):
return self.autoShootTimer.isActive()
-class GameBoard(QtGui.QWidget):
+class GameBoard(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("&Quit")
+ quit = QtWidgets.QPushButton("&Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
angle = LCDRange("ANGLE")
angle.setRange(5, 70)
@@ -266,24 +317,24 @@ class GameBoard(QtGui.QWidget):
self.connect(self.cannonField, QtCore.SIGNAL("hit()"), self.hit)
self.connect(self.cannonField, QtCore.SIGNAL("missed()"), self.missed)
- shoot = QtGui.QPushButton("&Shoot")
+ shoot = QtWidgets.QPushButton("&Shoot")
shoot.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(shoot, QtCore.SIGNAL("clicked()"), self.fire)
self.connect(self.cannonField, QtCore.SIGNAL("canShoot(bool)"),
shoot, QtCore.SLOT("setEnabled(bool)"))
- restart = QtGui.QPushButton("&New Game")
+ restart = QtWidgets.QPushButton("&New Game")
restart.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(restart, QtCore.SIGNAL("clicked()"), self.newGame)
- self.hits = QtGui.QLCDNumber(2)
- self.shotsLeft = QtGui.QLCDNumber(2)
- hitsLabel = QtGui.QLabel("HITS")
- shotsLeftLabel = QtGui.QLabel("SHOTS LEFT")
+ self.hits = QtWidgets.QLCDNumber(2)
+ self.shotsLeft = QtWidgets.QLCDNumber(2)
+ hitsLabel = QtWidgets.QLabel("HITS")
+ shotsLeftLabel = QtWidgets.QLabel("SHOTS LEFT")
- topLayout = QtGui.QHBoxLayout()
+ topLayout = QtWidgets.QHBoxLayout()
topLayout.addWidget(shoot)
topLayout.addWidget(self.hits)
topLayout.addWidget(hitsLabel)
@@ -292,11 +343,11 @@ class GameBoard(QtGui.QWidget):
topLayout.addStretch(1)
topLayout.addWidget(restart)
- leftLayout = QtGui.QVBoxLayout()
+ leftLayout = QtWidgets.QVBoxLayout()
leftLayout.addWidget(angle)
leftLayout.addWidget(force)
- gridLayout = QtGui.QGridLayout()
+ gridLayout = QtWidgets.QGridLayout()
gridLayout.addWidget(quit, 0, 0)
gridLayout.addLayout(topLayout, 0, 1)
gridLayout.addLayout(leftLayout, 1, 0)
@@ -310,12 +361,14 @@ class GameBoard(QtGui.QWidget):
self.newGame()
+ @QtCore.Slot()
def fire(self):
if self.cannonField.gameOver() or self.cannonField.isShooting():
return
self.shotsLeft.display(self.shotsLeft.intValue() - 1)
self.cannonField.shoot()
+ @QtCore.Slot()
def hit(self):
self.hits.display(self.hits.intValue() + 1)
if self.shotsLeft.intValue() == 0:
@@ -323,10 +376,12 @@ class GameBoard(QtGui.QWidget):
else:
self.cannonField.newTarget()
+ @QtCore.Slot()
def missed(self):
if self.shotsLeft.intValue() == 0:
self.cannonField.setGameOver()
+ @QtCore.Slot()
def newGame(self):
self.shotsLeft.display(15)
self.hits.display(0)
@@ -334,7 +389,7 @@ class GameBoard(QtGui.QWidget):
self.cannonField.newTarget()
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
board = GameBoard()
board.setGeometry(100, 100, 500, 355)
board.show()
diff --git a/examples/tutorial/t14.py b/examples/tutorial/t14.py
index e9287fd..609af40 100755..100644
--- a/examples/tutorial/t14.py
+++ b/examples/tutorial/t14.py
@@ -1,21 +1,62 @@
#!/usr/bin/env python
-# PyQt tutorial 14
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 14
import sys
import math
import random
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, text=None, parent=None):
- if isinstance(text, QtGui.QWidget):
+ if isinstance(text, QtWidgets.QWidget):
parent = text
text = None
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.init()
@@ -23,20 +64,20 @@ class LCDRange(QtGui.QWidget):
self.setText(text)
def init(self):
- lcd = QtGui.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
- self.label = QtGui.QLabel()
+ self.label = QtWidgets.QLabel()
self.label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
- self.label.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
+ self.label.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
lcd, QtCore.SLOT("display(int)"))
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
layout.addWidget(self.label)
@@ -47,6 +88,7 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
@@ -66,9 +108,14 @@ class LCDRange(QtGui.QWidget):
self.label.setText(text)
-class CannonField(QtGui.QWidget):
+class CannonField(QtWidgets.QWidget):
+ angleChanged = QtCore.Signal(int)
+ forceChanged = QtCore.Signal(int)
+ hit = QtCore.Signal()
+ missed = QtCore.Signal()
+ canShoot = QtCore.Signal(bool)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.currentAngle = 45
self.currentForce = 0
@@ -88,6 +135,7 @@ class CannonField(QtGui.QWidget):
def angle(self):
return self.currentAngle
+ @QtCore.Slot(int)
def setAngle(self, angle):
if angle < 5:
angle = 5
@@ -102,6 +150,7 @@ class CannonField(QtGui.QWidget):
def force(self):
return self.currentForce
+ @QtCore.Slot(int)
def setForce(self, force):
if force < 0:
force = 0
@@ -110,6 +159,7 @@ class CannonField(QtGui.QWidget):
self.currentForce = force;
self.emit(QtCore.SIGNAL("forceChanged(int)"), self.currentForce)
+ @QtCore.Slot()
def shoot(self):
if self.isShooting():
return
@@ -145,6 +195,7 @@ class CannonField(QtGui.QWidget):
self.update()
self.emit(QtCore.SIGNAL("canShoot(bool)"), True)
+ @QtCore.Slot()
def moveShot(self):
region = QtGui.QRegion(self.shotRect())
self.timerCount += 1
@@ -179,7 +230,7 @@ class CannonField(QtGui.QWidget):
if pos.y() >= self.height():
pos.setY(self.height() - 1)
rad = math.atan((float(self.rect().bottom()) - pos.y()) / pos.x())
- self.setAngle(QtCore.qRound(rad * 180 / 3.14159265))
+ self.setAngle(round(rad * 180 / 3.14159265))
def mouseReleaseEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
@@ -248,7 +299,7 @@ class CannonField(QtGui.QWidget):
y = y0 + vely * time - 0.5 * gravity * time * time
result = QtCore.QRect(0, 0, 6, 6)
- result.moveCenter(QtCore.QPoint(QtCore.qRound(x), self.height() - 1 - QtCore.qRound(y)))
+ result.moveCenter(QtCore.QPoint(round(x), self.height() - 1 - round(y)))
return result
def targetRect(self):
@@ -276,15 +327,15 @@ class CannonField(QtGui.QWidget):
return QtCore.QSize(400, 300)
-class GameBoard(QtGui.QWidget):
+class GameBoard(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("&Quit")
+ quit = QtWidgets.QPushButton("&Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
angle = LCDRange("ANGLE")
angle.setRange(5, 70)
@@ -292,8 +343,8 @@ class GameBoard(QtGui.QWidget):
force = LCDRange("FORCE")
force.setRange(10, 50)
- cannonBox = QtGui.QFrame()
- cannonBox.setFrameStyle(QtGui.QFrame.WinPanel | QtGui.QFrame.Sunken)
+ cannonBox = QtWidgets.QFrame()
+ cannonBox.setFrameStyle(QtWidgets.QFrame.WinPanel | QtWidgets.QFrame.Sunken)
self.cannonField = CannonField()
@@ -310,31 +361,31 @@ class GameBoard(QtGui.QWidget):
self.connect(self.cannonField, QtCore.SIGNAL("hit()"), self.hit)
self.connect(self.cannonField, QtCore.SIGNAL("missed()"), self.missed)
- shoot = QtGui.QPushButton("&Shoot")
+ shoot = QtWidgets.QPushButton("&Shoot")
shoot.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(shoot, QtCore.SIGNAL("clicked()"), self.fire)
self.connect(self.cannonField, QtCore.SIGNAL("canShoot(bool)"),
shoot, QtCore.SLOT("setEnabled(bool)"))
- restart = QtGui.QPushButton("&New Game")
+ restart = QtWidgets.QPushButton("&New Game")
restart.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(restart, QtCore.SIGNAL("clicked()"), self.newGame)
- self.hits = QtGui.QLCDNumber(2)
- self.shotsLeft = QtGui.QLCDNumber(2)
- hitsLabel = QtGui.QLabel("HITS")
- shotsLeftLabel = QtGui.QLabel("SHOTS LEFT")
+ self.hits = QtWidgets.QLCDNumber(2)
+ self.shotsLeft = QtWidgets.QLCDNumber(2)
+ hitsLabel = QtWidgets.QLabel("HITS")
+ shotsLeftLabel = QtWidgets.QLabel("SHOTS LEFT")
- QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Enter),
+ QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Enter),
self, self.fire)
- QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Return),
+ QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Return),
self, self.fire)
- QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_Q),
+ QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_Q),
self, QtCore.SLOT("close()"))
- topLayout = QtGui.QHBoxLayout()
+ topLayout = QtWidgets.QHBoxLayout()
topLayout.addWidget(shoot)
topLayout.addWidget(self.hits)
topLayout.addWidget(hitsLabel)
@@ -343,15 +394,15 @@ class GameBoard(QtGui.QWidget):
topLayout.addStretch(1)
topLayout.addWidget(restart)
- leftLayout = QtGui.QVBoxLayout()
+ leftLayout = QtWidgets.QVBoxLayout()
leftLayout.addWidget(angle)
leftLayout.addWidget(force)
- cannonLayout = QtGui.QVBoxLayout()
+ cannonLayout = QtWidgets.QVBoxLayout()
cannonLayout.addWidget(self.cannonField)
cannonBox.setLayout(cannonLayout)
- gridLayout = QtGui.QGridLayout()
+ gridLayout = QtWidgets.QGridLayout()
gridLayout.addWidget(quit, 0, 0)
gridLayout.addLayout(topLayout, 0, 1)
gridLayout.addLayout(leftLayout, 1, 0)
@@ -365,12 +416,14 @@ class GameBoard(QtGui.QWidget):
self.newGame()
+ @QtCore.Slot()
def fire(self):
if self.cannonField.gameOver() or self.cannonField.isShooting():
return
self.shotsLeft.display(self.shotsLeft.intValue() - 1)
self.cannonField.shoot()
+ @QtCore.Slot()
def hit(self):
self.hits.display(self.hits.intValue() + 1)
if self.shotsLeft.intValue() == 0:
@@ -378,10 +431,12 @@ class GameBoard(QtGui.QWidget):
else:
self.cannonField.newTarget()
+ @QtCore.Slot()
def missed(self):
if self.shotsLeft.intValue() == 0:
self.cannonField.setGameOver()
+ @QtCore.Slot()
def newGame(self):
self.shotsLeft.display(15)
self.hits.display(0)
@@ -389,7 +444,7 @@ class GameBoard(QtGui.QWidget):
self.cannonField.newTarget()
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
board = GameBoard()
board.setGeometry(100, 100, 500, 355)
board.show()
diff --git a/examples/tutorial/t2.py b/examples/tutorial/t2.py
index d670157..91ca2f3 100755..100644
--- a/examples/tutorial/t2.py
+++ b/examples/tutorial/t2.py
@@ -1,15 +1,55 @@
#!/usr/bin/env python
-# PyQt tutorial 2
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 2
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
-quit = QtGui.QPushButton("Quit")
+quit = QtWidgets.QPushButton("Quit")
quit.resize(75, 30)
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
diff --git a/examples/tutorial/t3.py b/examples/tutorial/t3.py
index a0f7339..9dc50a1 100755..100644
--- a/examples/tutorial/t3.py
+++ b/examples/tutorial/t3.py
@@ -1,18 +1,58 @@
#!/usr/bin/env python
-# PyQt tutorial 3
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 3
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
-window = QtGui.QWidget()
+window = QtWidgets.QWidget()
window.resize(200, 120)
-quit = QtGui.QPushButton("Quit", window)
+quit = QtWidgets.QPushButton("Quit", window)
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
quit.setGeometry(10, 40, 180, 40)
QtCore.QObject.connect(quit, QtCore.SIGNAL("clicked()"),
diff --git a/examples/tutorial/t4.py b/examples/tutorial/t4.py
index 0f6fc5d..77f593d 100755..100644
--- a/examples/tutorial/t4.py
+++ b/examples/tutorial/t4.py
@@ -1,27 +1,67 @@
#!/usr/bin/env python
-# PyQt tutorial 4
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 4
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.setFixedSize(200, 120)
- self.quit = QtGui.QPushButton("Quit", self)
+ self.quit = QtWidgets.QPushButton("Quit", self)
self.quit.setGeometry(62, 40, 75, 30)
self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(self.quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
diff --git a/examples/tutorial/t5.py b/examples/tutorial/t5.py
index 237c254..0fdd2ac 100755..100644
--- a/examples/tutorial/t5.py
+++ b/examples/tutorial/t5.py
@@ -1,38 +1,78 @@
#!/usr/bin/env python
-# PyQt tutorial 5
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 5
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("Quit")
+ quit = QtWidgets.QPushButton("Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
- lcd = QtGui.QLCDNumber(2)
+ lcd = QtWidgets.QLCDNumber(2)
- slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
slider.setRange(0, 99)
slider.setValue(0)
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
self.connect(slider, QtCore.SIGNAL("valueChanged(int)"),
lcd, QtCore.SLOT("display(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(quit);
layout.addWidget(lcd);
layout.addWidget(slider);
self.setLayout(layout);
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
diff --git a/examples/tutorial/t6.py b/examples/tutorial/t6.py
index 8636aba..d720433 100755..100644
--- a/examples/tutorial/t6.py
+++ b/examples/tutorial/t6.py
@@ -1,40 +1,80 @@
#!/usr/bin/env python
-# PyQt tutorial 6
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 6
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- lcd = QtGui.QLCDNumber(2)
- slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
slider.setRange(0, 99)
slider.setValue(0)
self.connect(slider, QtCore.SIGNAL("valueChanged(int)"),
lcd, QtCore.SLOT("display(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(slider)
self.setLayout(layout)
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("Quit")
+ quit = QtWidgets.QPushButton("Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
- grid = QtGui.QGridLayout()
- layout = QtGui.QVBoxLayout()
+ grid = QtWidgets.QGridLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(quit)
layout.addLayout(grid)
self.setLayout(layout)
@@ -45,7 +85,7 @@ class MyWidget(QtGui.QWidget):
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
diff --git a/examples/tutorial/t7.py b/examples/tutorial/t7.py
index b981ee9..a9c53f6 100755..100644
--- a/examples/tutorial/t7.py
+++ b/examples/tutorial/t7.py
@@ -1,19 +1,60 @@
#!/usr/bin/env python
-# PyQt tutorial 7
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 7
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- lcd = QtGui.QLCDNumber(2)
+ lcd = QtWidgets.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
@@ -22,7 +63,7 @@ class LCDRange(QtGui.QWidget):
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
self.setLayout(layout)
@@ -30,25 +71,26 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("Quit")
+ quit = QtWidgets.QPushButton("Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
- grid = QtGui.QGridLayout()
+ grid = QtWidgets.QGridLayout()
previousRange = None
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(quit)
layout.addLayout(grid)
self.setLayout(layout)
@@ -66,7 +108,7 @@ class MyWidget(QtGui.QWidget):
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
diff --git a/examples/tutorial/t8.py b/examples/tutorial/t8.py
index 697de9a..d023de1 100755..100644
--- a/examples/tutorial/t8.py
+++ b/examples/tutorial/t8.py
@@ -1,18 +1,59 @@
#!/usr/bin/env python
-# PyQt tutorial 8
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 8
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- lcd = QtGui.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
@@ -21,7 +62,7 @@ class LCDRange(QtGui.QWidget):
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
self.setLayout(layout)
@@ -31,6 +72,7 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
@@ -44,9 +86,10 @@ class LCDRange(QtGui.QWidget):
self.slider.setRange(minValue, maxValue)
-class CannonField(QtGui.QWidget):
+class CannonField(QtWidgets.QWidget):
+ angleChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.currentAngle = 45
self.setPalette(QtGui.QPalette(QtGui.QColor(250, 250, 200)))
@@ -55,6 +98,7 @@ class CannonField(QtGui.QWidget):
def angle(self):
return self.currentAngle
+ @QtCore.Slot(int)
def setAngle(self, angle):
if angle < 5:
angle = 5
@@ -71,15 +115,15 @@ class CannonField(QtGui.QWidget):
painter.drawText(200, 200, "Angle = %d" % self.currentAngle)
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("Quit")
+ quit = QtWidgets.QPushButton("Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
angle = LCDRange()
angle.setRange(5, 70)
@@ -91,7 +135,7 @@ class MyWidget(QtGui.QWidget):
self.connect(cannonField, QtCore.SIGNAL("angleChanged(int)"),
angle.setValue)
- gridLayout = QtGui.QGridLayout()
+ gridLayout = QtWidgets.QGridLayout()
gridLayout.addWidget(quit, 0, 0)
gridLayout.addWidget(angle, 1, 0)
gridLayout.addWidget(cannonField, 1, 1, 2, 1)
@@ -102,7 +146,7 @@ class MyWidget(QtGui.QWidget):
angle.setFocus()
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.setGeometry(100, 100, 500, 355)
widget.show()
diff --git a/examples/tutorial/t9.py b/examples/tutorial/t9.py
index 0a6bd59..37c0e65 100755..100644
--- a/examples/tutorial/t9.py
+++ b/examples/tutorial/t9.py
@@ -1,18 +1,59 @@
#!/usr/bin/env python
-# PyQt tutorial 9
+#############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide examples of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# PySide2 tutorial 9
import sys
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
-class LCDRange(QtGui.QWidget):
+class LCDRange(QtWidgets.QWidget):
+ valueChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- lcd = QtGui.QLCDNumber(2)
- self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ lcd = QtWidgets.QLCDNumber(2)
+ self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(0, 99)
self.slider.setValue(0)
@@ -21,7 +62,7 @@ class LCDRange(QtGui.QWidget):
self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),
self, QtCore.SIGNAL("valueChanged(int)"))
- layout = QtGui.QVBoxLayout()
+ layout = QtWidgets.QVBoxLayout()
layout.addWidget(lcd)
layout.addWidget(self.slider)
self.setLayout(layout)
@@ -31,6 +72,7 @@ class LCDRange(QtGui.QWidget):
def value(self):
return self.slider.value()
+ @QtCore.Slot(int)
def setValue(self, value):
self.slider.setValue(value)
@@ -44,9 +86,10 @@ class LCDRange(QtGui.QWidget):
self.slider.setRange(minValue, maxValue)
-class CannonField(QtGui.QWidget):
+class CannonField(QtWidgets.QWidget):
+ angleChanged = QtCore.Signal(int)
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.currentAngle = 45
self.setPalette(QtGui.QPalette(QtGui.QColor(250, 250, 200)))
@@ -55,6 +98,7 @@ class CannonField(QtGui.QWidget):
def angle(self):
return self.currentAngle
+ @QtCore.Slot(int)
def setAngle(self, angle):
if angle < 5:
angle = 5
@@ -78,15 +122,15 @@ class CannonField(QtGui.QWidget):
painter.drawRect(QtCore.QRect(33, -4, 15, 8))
-class MyWidget(QtGui.QWidget):
+class MyWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- quit = QtGui.QPushButton("Quit")
+ quit = QtWidgets.QPushButton("Quit")
quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(quit, QtCore.SIGNAL("clicked()"),
- QtGui.qApp, QtCore.SLOT("quit()"))
+ QtWidgets.qApp, QtCore.SLOT("quit()"))
angle = LCDRange()
angle.setRange(5, 70)
@@ -98,7 +142,7 @@ class MyWidget(QtGui.QWidget):
self.connect(cannonField, QtCore.SIGNAL("angleChanged(int)"),
angle.setValue)
- gridLayout = QtGui.QGridLayout()
+ gridLayout = QtWidgets.QGridLayout()
gridLayout.addWidget(quit, 0, 0)
gridLayout.addWidget(angle, 1, 0)
gridLayout.addWidget(cannonField, 1, 1, 2, 1)
@@ -109,7 +153,7 @@ class MyWidget(QtGui.QWidget):
angle.setFocus()
-app = QtGui.QApplication(sys.argv)
+app = QtWidgets.QApplication(sys.argv)
widget = MyWidget()
widget.setGeometry(100, 100, 500, 355)
widget.show()