diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-12 08:17:07 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-12 08:17:07 +0200 |
commit | 30724622333ffc8bce61f7e19217977eebbf9564 (patch) | |
tree | 172487d1478cc478857d46cb445db59ca3601448 /examples/widgets/graphicsview | |
parent | 1a66d7be29902fc041fe53ef280c237d3c3f216b (diff) | |
parent | 8847a47aad95d7f85d5e184071bf95c44826c4c7 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I7f16e4f178bff9c37af3b7a9d536c5d6f42c66fb
Diffstat (limited to 'examples/widgets/graphicsview')
3 files changed, 20 insertions, 14 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) 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): 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() |