aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-03-19 15:31:46 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-19 19:14:53 +0000
commitb4ac76ea49cb827d89d5048d821ddaf9bae343f3 (patch)
tree33e72a63f43030fc968849d8597ec1a5baf36b4f
parenta9aef8f523472d25f605a67d7df4a009084c22af (diff)
Port examples away from deprecated QMouseEvent::pos()
As a drive by, fix the left-over QtCharts callout example to work after 227020b118fa38ada1d8bd579593dae61f6e3881. Task-number: PYSIDE-1122 Change-Id: I945b57950014e882d4efd3cb0cab47262ad108b6 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit 306ecd14ccba188a1c88061715456c329c1ff79c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/charts/callout/callout.py17
-rw-r--r--examples/corelib/threads/mandelbrot.py21
-rw-r--r--examples/opengl/hellogl2/hellogl2.py13
-rw-r--r--examples/sql/books/bookdelegate.py2
-rw-r--r--examples/widgets/draganddrop/draggabletext/draggabletext.py4
-rw-r--r--examples/widgets/tutorials/cannon/t14.py4
6 files changed, 32 insertions, 29 deletions
diff --git a/examples/charts/callout/callout.py b/examples/charts/callout/callout.py
index 666b2aae5..4a34e07f1 100644
--- a/examples/charts/callout/callout.py
+++ b/examples/charts/callout/callout.py
@@ -45,7 +45,7 @@ import sys
from PySide6.QtWidgets import (QApplication, QGraphicsScene,
QGraphicsView, QGraphicsSimpleTextItem, QGraphicsItem)
from PySide6.QtCore import Qt, QPointF, QRectF, QRect
-from PySide6.QtCharts import QtCharts
+from PySide6.QtCharts import QChart, QLineSeries, QSplineSeries
from PySide6.QtGui import QPainter, QFont, QFontMetrics, QPainterPath, QColor
@@ -162,12 +162,12 @@ class View(QGraphicsView):
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# Chart
- self._chart = QtCharts.QChart()
+ self._chart = QChart()
self._chart.setMinimumSize(640, 480)
self._chart.setTitle("Hover the line to show callout. Click the line "
"to make it stay")
self._chart.legend().hide()
- self.series = QtCharts.QLineSeries()
+ self.series = QLineSeries()
self.series.append(1, 3)
self.series.append(4, 5)
self.series.append(5, 4.5)
@@ -175,7 +175,7 @@ class View(QGraphicsView):
self.series.append(11, 2)
self._chart.addSeries(self.series)
- self.series2 = QtCharts.QSplineSeries()
+ self.series2 = QSplineSeries()
self.series2.append(1.6, 1.4)
self.series2.append(2.4, 3.5)
self.series2.append(3.7, 2.5)
@@ -225,10 +225,11 @@ class View(QGraphicsView):
def mouseMoveEvent(self, event):
- self._coordX.setText("X: {0:.2f}"
- .format(self._chart.mapToValue(event.pos()).x()))
- self._coordY.setText("Y: {0:.2f}"
- .format(self._chart.mapToValue(event.pos()).y()))
+ pos = self._chart.mapToValue(event.position().toPoint())
+ x = pos.x()
+ y = pos.y()
+ self._coordX.setText(f"X: {x:.2f}")
+ self._coordY.setText(f"Y: {y:.2f}")
QGraphicsView.mouseMoveEvent(self, event)
def keepCallout(self):
diff --git a/examples/corelib/threads/mandelbrot.py b/examples/corelib/threads/mandelbrot.py
index 2d82cd65a..1cdf903d5 100644
--- a/examples/corelib/threads/mandelbrot.py
+++ b/examples/corelib/threads/mandelbrot.py
@@ -42,7 +42,7 @@
"""PySide6 port of the corelib/threads/mandelbrot example from Qt v5.x, originating from PyQt"""
-from PySide6.QtCore import (Signal, QMutex, QMutexLocker, QPoint, QSize, Qt,
+from PySide6.QtCore import (Signal, QMutex, QMutexLocker, QPointF, QSize, Qt,
QThread, QWaitCondition)
from PySide6.QtGui import QColor, QImage, QPainter, QPixmap, qRgb
from PySide6.QtWidgets import QApplication, QWidget
@@ -215,8 +215,8 @@ class MandelbrotWidget(QWidget):
self.thread = RenderThread()
self.pixmap = QPixmap()
- self.pixmapOffset = QPoint()
- self.lastDragPos = QPoint()
+ self.pixmapOffset = QPointF()
+ self.lastDragPos = QPointF()
self.centerX = DefaultCenterX
self.centerY = DefaultCenterY
@@ -295,18 +295,19 @@ class MandelbrotWidget(QWidget):
def mousePressEvent(self, event):
if event.buttons() == Qt.LeftButton:
- self.lastDragPos = QPoint(event.pos())
+ self.lastDragPos = event.position()
def mouseMoveEvent(self, event):
if event.buttons() & Qt.LeftButton:
- self.pixmapOffset += event.pos() - self.lastDragPos
- self.lastDragPos = QPoint(event.pos())
+ pos = event.position()
+ self.pixmapOffset += pos - self.lastDragPos
+ self.lastDragPos = pos
self.update()
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
- self.pixmapOffset += event.pos() - self.lastDragPos
- self.lastDragPos = QPoint()
+ self.pixmapOffset += event.position() - self.lastDragPos
+ self.lastDragPos = QPointF()
deltaX = (self.width() - self.pixmap.width()) / 2 - self.pixmapOffset.x()
deltaY = (self.height() - self.pixmap.height()) / 2 - self.pixmapOffset.y()
@@ -317,8 +318,8 @@ class MandelbrotWidget(QWidget):
return
self.pixmap = QPixmap.fromImage(image)
- self.pixmapOffset = QPoint()
- self.lastDragPosition = QPoint()
+ self.pixmapOffset = QPointF()
+ self.lastDragPosition = QPointF()
self.pixmapScale = scaleFactor
self.update()
diff --git a/examples/opengl/hellogl2/hellogl2.py b/examples/opengl/hellogl2/hellogl2.py
index bcffdf3c9..56301e047 100644
--- a/examples/opengl/hellogl2/hellogl2.py
+++ b/examples/opengl/hellogl2/hellogl2.py
@@ -46,7 +46,7 @@ import sys
import math
import numpy
import ctypes
-from PySide6.QtCore import QCoreApplication, Signal, SIGNAL, SLOT, Qt, QSize, QPoint
+from PySide6.QtCore import QCoreApplication, Signal, SIGNAL, SLOT, Qt, QSize, QPointF
from PySide6.QtGui import (QVector3D, QOpenGLFunctions,
QMatrix4x4, QOpenGLContext, QSurfaceFormat)
from PySide6.QtOpenGL import (QOpenGLVertexArrayObject, QOpenGLBuffer,
@@ -231,7 +231,7 @@ class GLWidget(QOpenGLWidget, QOpenGLFunctions):
self.xRot = 0
self.yRot = 0
self.zRot = 0
- self.lastPos = 0
+ self.lastPos = QPointF()
self.logo = Logo()
self.vao = QOpenGLVertexArrayObject()
self.logoVbo = QOpenGLBuffer()
@@ -437,11 +437,12 @@ class GLWidget(QOpenGLWidget, QOpenGLFunctions):
self.proj.perspective(45, width / height, 0.01, 100)
def mousePressEvent(self, event):
- self.lastPos = QPoint(event.pos())
+ self.lastPos = event.position()
def mouseMoveEvent(self, event):
- dx = event.x() - self.lastPos.x()
- dy = event.y() - self.lastPos.y()
+ pos = event.position()
+ dx = pos.x() - self.lastPos.x()
+ dy = pos.y() - self.lastPos.y()
if event.buttons() & Qt.LeftButton:
self.setXRotation(self.xRot + 8 * dy)
@@ -450,7 +451,7 @@ class GLWidget(QOpenGLWidget, QOpenGLFunctions):
self.setXRotation(self.xRot + 8 * dy)
self.setZRotation(self.zRot + 8 * dx)
- self.lastPos = QPoint(event.pos())
+ self.lastPos = pos
if __name__ == '__main__':
app = QApplication(sys.argv)
diff --git a/examples/sql/books/bookdelegate.py b/examples/sql/books/bookdelegate.py
index d44abb5b1..f8b199d76 100644
--- a/examples/sql/books/bookdelegate.py
+++ b/examples/sql/books/bookdelegate.py
@@ -112,7 +112,7 @@ class BookDelegate(QSqlRelationalDelegate):
return False
if event.type() == QEvent.MouseButtonPress:
- mouse_pos = event.pos()
+ mouse_pos = event.position()
new_stars = int(0.7 + (mouse_pos.x() - option.rect.x()) / self.star.width())
stars = max(0, min(new_stars, 5))
model.setData(index, stars)
diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.py b/examples/widgets/draganddrop/draggabletext/draggabletext.py
index 480f3f4c6..a9ef72c41 100644
--- a/examples/widgets/draganddrop/draggabletext/draggabletext.py
+++ b/examples/widgets/draganddrop/draggabletext/draggabletext.py
@@ -58,7 +58,7 @@ class DragLabel(QLabel):
self.setFrameShadow(QFrame.Raised)
def mousePressEvent(self, event):
- hotSpot = event.pos()
+ hotSpot = event.position().toPoint()
mimeData = QMimeData()
mimeData.setText(self.text())
@@ -121,7 +121,7 @@ class DragWidget(QWidget):
if event.mimeData().hasText():
mime = event.mimeData()
pieces = mime.text().split()
- position = event.pos()
+ position = event.position().toPoint()
hotSpot = QPoint()
hotSpotPos = mime.data('application/x-hotspot').split(' ')
diff --git a/examples/widgets/tutorials/cannon/t14.py b/examples/widgets/tutorials/cannon/t14.py
index d558d2e61..19fb95ac8 100644
--- a/examples/widgets/tutorials/cannon/t14.py
+++ b/examples/widgets/tutorials/cannon/t14.py
@@ -217,13 +217,13 @@ class CannonField(QtWidgets.QWidget):
def mousePressEvent(self, event):
if event.button() != QtCore.Qt.LeftButton:
return
- if self.barrelHit(event.pos()):
+ if self.barrelHit(event.position().toPoint()):
self.barrelPressed = True
def mouseMoveEvent(self, event):
if not self.barrelPressed:
return
- pos = event.pos()
+ pos = event.position().toPoint()
if pos.x() <= 0:
pos.setX(1)
if pos.y() >= self.height():