aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py')
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py11
1 files changed, 6 insertions, 5 deletions
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):