aboutsummaryrefslogtreecommitdiffstats
path: root/examples/graphicsview/collidingmice/collidingmice.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/graphicsview/collidingmice/collidingmice.py')
-rwxr-xr-xexamples/graphicsview/collidingmice/collidingmice.py72
1 files changed, 46 insertions, 26 deletions
diff --git a/examples/graphicsview/collidingmice/collidingmice.py b/examples/graphicsview/collidingmice/collidingmice.py
index 0156650..23f908f 100755
--- a/examples/graphicsview/collidingmice/collidingmice.py
+++ b/examples/graphicsview/collidingmice/collidingmice.py
@@ -1,34 +1,54 @@
#!/usr/bin/env python
-############################################################################
+#############################################################################
##
-## Copyright (C) 2006-2006 Trolltech ASA. All rights reserved.
+## Copyright (C) 2013 Riverbank Computing Limited.
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
##
-## This file is part of the example classes of the Qt Toolkit.
+## This file is part of the PySide examples of the Qt Toolkit.
##
-## Licensees holding a valid Qt License Agreement may use this file in
-## accordance with the rights, responsibilities and obligations
-## contained therein. Please consult your licensing agreement or
-## contact sales@trolltech.com if any conditions of this licensing
-## agreement are not clear to you.
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
##
-## Further information about Qt licensing is available at:
-## http://www.trolltech.com/products/qt/licensing.html or by
-## contacting info@trolltech.com.
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
##
-## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
-############################################################################
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
import math
-from PySide2 import QtCore, QtGui
+from PySide2 import QtCore, QtGui, QtWidgets
import mice_rc
-class Mouse(QtGui.QGraphicsItem):
+class Mouse(QtWidgets.QGraphicsItem):
Pi = math.pi
TwoPi = 2.0 * Pi
@@ -46,10 +66,10 @@ class Mouse(QtGui.QGraphicsItem):
self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256,
QtCore.qrand() % 256)
- self.rotate(QtCore.qrand() % (360 * 16))
+ self.setTransform(QtGui.QTransform().rotate(QtCore.qrand() % (360 * 16)))
# In the C++ version of this example, this class is also derived from
- # QObject in order to receive timer events. PyQt does not support
+ # QObject in order to receive timer events. PySide2 does not support
# deriving from more than one wrapped class so we just create an
# explicit timer instead.
self.timer = QtCore.QTimer()
@@ -161,7 +181,7 @@ class Mouse(QtGui.QGraphicsItem):
dx = math.sin(self.angle) * 10
self.mouseEyeDirection = [dx / 5, 0.0][QtCore.qAbs(dx / 5) < 1]
- self.rotate(dx)
+ self.setTransform(QtGui.QTransform().rotate(dx))
self.setPos(self.mapToParent(0, -(3 + math.sin(self.speed) * 3)))
@@ -171,12 +191,12 @@ if __name__ == '__main__':
MouseCount = 7
- app = QtGui.QApplication(sys.argv)
+ app = QtWidgets.QApplication(sys.argv)
QtCore.qsrand(QtCore.QTime(0,0,0).secsTo(QtCore.QTime.currentTime()))
- scene = QtGui.QGraphicsScene()
+ scene = QtWidgets.QGraphicsScene()
scene.setSceneRect(-300, -300, 600, 600)
- scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
+ scene.setItemIndexMethod(QtWidgets.QGraphicsScene.NoIndex)
for i in range(MouseCount):
mouse = Mouse()
@@ -184,12 +204,12 @@ if __name__ == '__main__':
math.cos((i * 6.28) / MouseCount) * 200)
scene.addItem(mouse)
- view = QtGui.QGraphicsView(scene)
+ view = QtWidgets.QGraphicsView(scene)
view.setRenderHint(QtGui.QPainter.Antialiasing)
view.setBackgroundBrush(QtGui.QBrush(QtGui.QPixmap(':/images/cheese.jpg')))
- view.setCacheMode(QtGui.QGraphicsView.CacheBackground)
- view.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate)
- view.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
+ view.setCacheMode(QtWidgets.QGraphicsView.CacheBackground)
+ view.setViewportUpdateMode(QtWidgets.QGraphicsView.BoundingRectViewportUpdate)
+ view.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag)
view.setWindowTitle("Colliding Mice")
view.resize(400, 300)
view.show()