diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-08 15:30:00 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-08 16:22:24 +0200 |
commit | a5c8bb4305f994fdaca11a642231ea60273bf553 (patch) | |
tree | 613cb90dd5ac6490543de3f95c83fd9c28bc72c3 /examples | |
parent | 2ed45ce8991408de91d7e02a2b80a09a2d9e5083 (diff) |
Replace deprecated API in examples
- Replace qrand() by QRandomGenerator
- Replace QMatrix by QTransform
Task-number: PYSIDE-841
Task-number: PYSIDE-1339
Task-number: PYSIDE-904
Change-Id: I8609a9ce90a6df1cb7c7f1b9aab61695edf41a3f
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tutorial/t14.py | 2 | ||||
-rw-r--r-- | examples/widgets/graphicsview/collidingmice/collidingmice.py | 16 | ||||
-rw-r--r-- | examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py | 11 | ||||
-rw-r--r-- | examples/widgets/graphicsview/elasticnodes.py | 7 |
4 files changed, 21 insertions, 15 deletions
diff --git a/examples/tutorial/t14.py b/examples/tutorial/t14.py index 0fcfa74c4..2d5e1a171 100644 --- a/examples/tutorial/t14.py +++ b/examples/tutorial/t14.py @@ -310,7 +310,7 @@ class CannonField(QtWidgets.QWidget): return QtCore.QRect(145, self.height() - 100, 15, 99) def barrelHit(self, pos): - matrix = QtGui.QMatrix() + matrix = QtGui.QTransform() matrix.translate(0, self.height()) matrix.rotate(-self.currentAngle) matrix, invertible = matrix.inverted() diff --git a/examples/widgets/graphicsview/collidingmice/collidingmice.py b/examples/widgets/graphicsview/collidingmice/collidingmice.py index 08a62d0e0..2203cb381 100644 --- a/examples/widgets/graphicsview/collidingmice/collidingmice.py +++ b/examples/widgets/graphicsview/collidingmice/collidingmice.py @@ -47,6 +47,10 @@ from PySide2 import QtCore, QtGui, QtWidgets import mice_rc +def random(boundary): + return QtCore.QRandomGenerator.global_().bounded(boundary) + + class Mouse(QtWidgets.QGraphicsItem): Pi = math.pi TwoPi = 2.0 * Pi @@ -62,10 +66,9 @@ class Mouse(QtWidgets.QGraphicsItem): self.angle = 0.0 self.speed = 0.0 self.mouseEyeDirection = 0.0 - self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256, - QtCore.qrand() % 256) + self.color = QtGui.QColor(random(256), random(256), random(256)) - self.setTransform(QtGui.QTransform().rotate(QtCore.qrand() % (360 * 16))) + self.setTransform(QtGui.QTransform().rotate(random(360 * 16))) # In the C++ version of this example, this class is also derived from # QObject in order to receive timer events. PySide2 does not support @@ -171,11 +174,11 @@ class Mouse(QtWidgets.QGraphicsItem): # Add some random movement. if len(dangerMice) > 1 and (QtCore.qrand() % 10) == 0: if QtCore.qrand() % 1: - self.angle += (QtCore.qrand() % 100) / 500.0 + self.angle += random(100) / 500.0 else: - self.angle -= (QtCore.qrand() % 100) / 500.0 + self.angle -= random(100) / 500.0 - self.speed += (-50 + QtCore.qrand() % 100) / 100.0 + self.speed += (-50 + random(100)) / 100.0 dx = math.sin(self.angle) * 10 self.mouseEyeDirection = [dx / 5, 0.0][QtCore.qAbs(dx / 5) < 1] @@ -191,7 +194,6 @@ if __name__ == '__main__': MouseCount = 7 app = QtWidgets.QApplication(sys.argv) - QtCore.qsrand(QtCore.QTime(0,0,0).secsTo(QtCore.QTime.currentTime())) scene = QtWidgets.QGraphicsScene() scene.setSceneRect(-300, -300, 600, 600) diff --git a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py index 68a54d552..73ca02dca 100644 --- a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py +++ b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py @@ -45,14 +45,17 @@ from PySide2 import QtCore, QtGui, QtWidgets import dragdroprobot_rc +def random(boundary): + return QtCore.QRandomGenerator.global_().bounded(boundary) + + class ColorItem(QtWidgets.QGraphicsItem): n = 0 def __init__(self): super(ColorItem, self).__init__() - self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256, - QtCore.qrand() % 256) + self.color = QtGui.QColor(random(256), random(256), random(256)) self.setToolTip( "QColor(%d, %d, %d)\nClick and drag this color onto the robot!" % @@ -87,7 +90,7 @@ class ColorItem(QtWidgets.QGraphicsItem): drag.setMimeData(mime) ColorItem.n += 1 - if ColorItem.n > 2 and QtCore.qrand() % 3 == 0: + if ColorItem.n > 2 and random(3) == 0: image = QtGui.QImage(':/images/head.png') mime.setImageData(image) drag.setPixmap(QtGui.QPixmap.fromImage(image).scaled(30,40)) @@ -261,8 +264,6 @@ if __name__== '__main__': app = QtWidgets.QApplication(sys.argv) - QtCore.qsrand(QtCore.QTime(0, 0, 0).secsTo(QtCore.QTime.currentTime())) - scene = QtWidgets.QGraphicsScene(-200, -200, 400, 400) for i in range(10): diff --git a/examples/widgets/graphicsview/elasticnodes.py b/examples/widgets/graphicsview/elasticnodes.py index 48feffc85..f5d229b13 100644 --- a/examples/widgets/graphicsview/elasticnodes.py +++ b/examples/widgets/graphicsview/elasticnodes.py @@ -46,6 +46,10 @@ import math from PySide2 import QtCore, QtGui, QtWidgets +def random(boundary): + return QtCore.QRandomGenerator.global_().bounded(boundary) + + class Edge(QtWidgets.QGraphicsItem): Pi = math.pi TwoPi = 2.0 * Pi @@ -338,7 +342,7 @@ class GraphWidget(QtWidgets.QGraphicsView): elif key == QtCore.Qt.Key_Space or key == QtCore.Qt.Key_Enter: for item in self.scene().items(): if isinstance(item, Node): - item.setPos(-150 + QtCore.qrand() % 300, -150 + QtCore.qrand() % 300) + item.setPos(-150 + random(300), -150 + random(300)) else: QtWidgets.QGraphicsView.keyPressEvent(self, event) @@ -405,7 +409,6 @@ class GraphWidget(QtWidgets.QGraphicsView): if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) - QtCore.qsrand(QtCore.QTime(0,0,0).secsTo(QtCore.QTime.currentTime())) widget = GraphWidget() widget.show() |