aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/graphicsview/collidingmice
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-08 15:30:00 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-08 16:22:24 +0200
commita5c8bb4305f994fdaca11a642231ea60273bf553 (patch)
tree613cb90dd5ac6490543de3f95c83fd9c28bc72c3 /examples/widgets/graphicsview/collidingmice
parent2ed45ce8991408de91d7e02a2b80a09a2d9e5083 (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/widgets/graphicsview/collidingmice')
-rw-r--r--examples/widgets/graphicsview/collidingmice/collidingmice.py16
1 files changed, 9 insertions, 7 deletions
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)