def keyPressEvent(self, event): BaseItem.keyPressEvent(self, event) step = 1 if event.modifiers() & Qt.ShiftModifier: step = 5 ds = {Qt.Key_Left: (-step, 0), Qt.Key_Right: (step, 0), Qt.Key_Up: (0, -step), Qt.Key_Down: (0, step) }.get(event.key(), None) if ds is not None: self.moveBy(*ds) event.accept()
def keyPressEvent(self, event): BaseItem.keyPressEvent(self, event) step = 1 if event.modifiers() & Qt.ShiftModifier: step = 5 ds = {Qt.Key_Left: (-step, 0), Qt.Key_Right: (step, 0), Qt.Key_Up: (0, -step), Qt.Key_Down: (0, step), }.get(event.key(), None) if ds is not None: if event.modifiers() & Qt.ControlModifier: centre_x=self._rect.center().x()#self._rect.x()+self._rect.width()/2 centre_y=self._rect.center().y()#self._rect.y()+self._rect.height()/2 ratio=self._rect.width()/self._rect.height() changed=False if (ds[0]==0): # change of height newh=self._rect.height() + ds[1]*-2 if (newh>10): h = newh w = ratio*h changed=True else: # change of width neww=self._rect.width() + ds[0]*2 if (neww>10): w = neww h = w/ratio changed=True if (changed): x = centre_x - w/2 y = centre_y - h/2 if (x>=0 and y>=0 and x+w<=self._max_w and y+h<=self._max_h): rect = QRectF(QPointF(x,y), QSizeF(w, h)).normalized() self._updateRect(rect) else: rect = self._rect.adjusted(*(ds + ds)) if (rect.x()>=0 and rect.y()>=0 and rect.x()+rect.width()<=self._max_w and rect.y()+rect.height()<=self._max_h): self._updateRect(rect) self.updateModel() event.accept()