aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-12 08:17:07 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-12 08:17:07 +0200
commit30724622333ffc8bce61f7e19217977eebbf9564 (patch)
tree172487d1478cc478857d46cb445db59ca3601448 /examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py
parent1a66d7be29902fc041fe53ef280c237d3c3f216b (diff)
parent8847a47aad95d7f85d5e184071bf95c44826c4c7 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
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 035358e65..8defc6d07 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))
@@ -262,8 +265,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):