def __init__(self, scene): QGraphicsView.__init__(self, scene) self.scene = scene self.setBackgroundBrush(QBrush(Color.background)) self.antialiasing = True self.setHorizontalScrollBarPolicy(qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(qt.ScrollBarAlwaysOff)
def mousePressEvent(self, e): if e.button()==qt.MidButton or (e.button()==qt.RightButton and not self.scene.use_rightclick and not self.scene.itemAt(self.mapToScene(e.pos()), QTransform())): fake = QMouseEvent(e.type(), e.pos(), qt.LeftButton, qt.LeftButton, e.modifiers()) self.scene.supress = True self.setDragMode(QGraphicsView.ScrollHandDrag) QGraphicsView.mousePressEvent(self, fake) else: QGraphicsView.mousePressEvent(self, e)
def mouseReleaseEvent(self, e): if e.button()==qt.MidButton or (e.button()==qt.RightButton and self.scene.supress): fake = QMouseEvent(e.type(), e.pos(), qt.LeftButton, qt.LeftButton, e.modifiers()) QGraphicsView.mouseReleaseEvent(self, fake) self.setDragMode(QGraphicsView.NoDrag) self.scene.supress = False else: QGraphicsView.mouseReleaseEvent(self, e)
def __init__(self, scene): QGraphicsView.__init__(self, scene) self.scene = scene self.setBackgroundBrush(QBrush(qt.white)) self.setRenderHints(self.renderHints()|QPainter.Antialiasing) self.setHorizontalScrollBarPolicy(qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(qt.ScrollBarAlwaysOff) self.scene.text_changed.connect(self.viewport().update) # ensure a full redraw
def keyPressEvent(self, e): evt = self._get_event(e, QEvent.MouseButtonPress) if evt: self.mousePressEvent(evt) else: QGraphicsView.keyPressEvent(self, e) item = self.itemAt(self.mapFromGlobal(QCursor.pos())) if item: item.keyPressEvent(e)
def __init__(self, scene): QGraphicsView.__init__(self, scene) self.scene = scene self.setBackgroundBrush(QBrush(qt.white)) self.setResizeAnchor(QGraphicsView.AnchorViewCenter) self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.setRenderHints(self.renderHints()|QPainter.Antialiasing) self.setHorizontalScrollBarPolicy(qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(qt.ScrollBarAlwaysOff) inf = -1e10 self.setSceneRect(QRectF(QPointF(-inf, -inf), QPointF(inf, inf))) self.scale(50, 50) #*1.00955
def paintEvent(self, e): QGraphicsView.paintEvent(self, e) g = QPainter(self.viewport()) g.setRenderHints(self.renderHints()) try: self._info_font except AttributeError: self._info_font = g.font() multiply_font_size(self._info_font, 3) try: txt = ('{r} ({m})' if self.scene.mistakes else '{r}').format(r=self.scene.remaining, m=self.scene.mistakes) g.setFont(self._info_font) g.drawText(self.viewport().rect().adjusted(5, 2, -5, -2), qt.AlignTop|qt.AlignRight, txt) except AttributeError: pass
def resizeEvent(self, e): QGraphicsView.resizeEvent(self, e) if not self.scene.playtest: self.fit()
def keyReleaseEvent(self, e): evt = self._get_event(e, QEvent.MouseButtonRelease) if evt: self.mouseReleaseEvent(evt) else: QGraphicsView.keyReleaseEvent(self, e)