def __init__(self, parent=None): """generate a fitting view with our favourite properties""" QGraphicsView.__init__(self, parent) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) vpol = QSizePolicy() vpol.setHorizontalPolicy(QSizePolicy.Expanding) vpol.setVerticalPolicy(QSizePolicy.Expanding) self.setSizePolicy(vpol) self.setRenderHint(QPainter.Antialiasing) self.setRenderHint(QPainter.SmoothPixmapTransform) self.setStyleSheet('background: transparent') self.setFrameStyle(QFrame.NoFrame) self.tilePressed = None self.dragObject = None self.setFocus()
def mouseMoveEvent(self, event): """selects the correct uiTile""" tilePressed = self.tilePressed self.tilePressed = None if tilePressed: board = tilePressed.board if board and board.tileDragEnabled: self.dragObject = self.drag(tilePressed) self.dragObject.exec_(Qt.MoveAction) self.dragObject = None return return QGraphicsView.mouseMoveEvent(self, event)
def mouseReleaseEvent(self, event): """release self.tilePressed""" self.tilePressed = None return QGraphicsView.mouseReleaseEvent(self, event)