Created
February 18, 2018 01:17
-
-
Save tpoveda/d23636898739dbc46db16be4e05a86f8 to your computer and use it in GitHub Desktop.
Drag & Drop in QGraphicsView (PyQt - PySide)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Qt import QtCore as qc | |
from Qt import QtGui as qg | |
from Qt import QtWidgets as qw | |
class ControlView(qw.QGraphicsView): | |
""" | |
Base class to create the control view | |
""" | |
def __init__(self, scene, parent): | |
""" | |
@param scene: QGraphicsScene that defines the scene we want to visualize | |
@param parent: QWidget parent | |
""" | |
super(ControlView, self).__init__(parent) | |
self.setObjectName('ControlView') | |
self.setScene(scene) | |
self.setRenderHint(qg.QPainter.Antialiasing) | |
self.setTransformationAnchor(qw.QGraphicsView.AnchorUnderMouse) | |
self.setViewportUpdateMode(qw.QGraphicsView.SmartViewportUpdate) | |
self.setAcceptDrops(True) | |
self.setDragMode(qw.QGraphicsView.ScrollHandDrag) | |
self.dragOver = False | |
def dragMoveEvent(self, event): | |
pass | |
def dragEnterEvent(self, event): | |
if event.mimeData().hasText(): | |
event.setAccepted(True) | |
self.dragOver = True | |
self.update() | |
def dropEvent(self, event): | |
pos = event.pos() | |
event.acceptProposedAction() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment