From 955f1c37a6a99bbef018a928b338a1c7e024f01d Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Fri, 12 Feb 2021 13:30:06 -0800 Subject: [PATCH] Use QPointF instead of QPoint for float input --- pyqtgraph/widgets/JoystickButton.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pyqtgraph/widgets/JoystickButton.py b/pyqtgraph/widgets/JoystickButton.py index b668d82d..88955934 100644 --- a/pyqtgraph/widgets/JoystickButton.py +++ b/pyqtgraph/widgets/JoystickButton.py @@ -11,7 +11,7 @@ class JoystickButton(QtGui.QPushButton): self.radius = 200 self.setCheckable(True) self.state = None - self.setState(0,0) + self.setState(0, 0) self.setFixedWidth(50) self.setFixedHeight(50) @@ -42,21 +42,24 @@ class JoystickButton(QtGui.QPushButton): def setState(self, *xy): xy = list(xy) d = (xy[0]**2 + xy[1]**2)**0.5 - nxy = [0,0] + nxy = [0, 0] for i in [0,1]: if xy[i] == 0: nxy[i] = 0 else: - nxy[i] = xy[i]/d + nxy[i] = xy[i] / d if d > self.radius: d = self.radius - d = (d/self.radius)**2 - xy = [nxy[0]*d, nxy[1]*d] + d = (d / self.radius) ** 2 + xy = [nxy[0] * d, nxy[1] * d] - w2 = self.width()/2. - h2 = self.height()/2 - self.spotPos = QtCore.QPoint(w2*(1+xy[0]), h2*(1-xy[1])) + w2 = self.width() / 2 + h2 = self.height() / 2 + self.spotPos = QtCore.QPoint( + int(w2 * (1 + xy[0])), + int(h2 * (1 - xy[1])) + ) self.update() if self.state == xy: return @@ -67,7 +70,12 @@ class JoystickButton(QtGui.QPushButton): super().paintEvent(ev) p = QtGui.QPainter(self) p.setBrush(QtGui.QBrush(QtGui.QColor(0,0,0))) - p.drawEllipse(self.spotPos.x()-3,self.spotPos.y()-3,6,6) + p.drawEllipse( + self.spotPos.x() - 3, + self.spotPos.y() - 3, + 6, + 6 + ) def resizeEvent(self, ev): self.setState(*self.state)