Im working on a maya GUI and I created a drag selection box using QRubberBand. Now i'm trying to move it when I hold 'Alt'. The problem is that when I move the QRubberBand, it moves from the origin of the box, like this Currently.

What I'm trying to do is get it moving from the end point of the box, like this expected behaviour
.
Here is the code:
from PySide2 import QtCore, QtGui, QtWidgets
class Ui_Form(QtWidgets.QWidget):
def __init__(self):
super(Ui_Form, self).__init__()
self.rubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle, self)
self.setupUi(self)
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
if event.modifiers() == QtCore.Qt.ShiftModifier:
print 'shift is selected'
elif event.modifiers() == QtCore.Qt.CTRL:
print 'Ctrl is selected'
else:
print 'Reseting selection'
self.origin = event.pos()
self.drag_selection = QtCore.QRect(self.origin, QtCore.QSize())
self.rubberBand.setGeometry(self.drag_selection)
self.rubberBand.show()
def mouseMoveEvent(self, event):
if event.modifiers() == QtCore.Qt.AltModifier:
self.rubberBand.move(event.pos())
self.origin = self.rubberBand.pos()
else:
self.drag_selection = QtCore.QRect(self.origin, event.pos()).normalized()
self.rubberBand.setGeometry(self.drag_selection)
def mouseReleaseEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.rubberBand.hide()
if event.modifiers() == QtCore.Qt.CTRL:
print 'Removing from selection'
else:
print 'Selecting'
