Created
September 20, 2023 19:47
-
-
Save jcfr/a91f00aec4aac83567d70a2d466236ba to your computer and use it in GitHub Desktop.
Override drag and drop behavior associated with Slicer main window
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
class EventManager(qt.QObject): | |
def eventFilter(self, object, event): | |
""" | |
Custom event filter for Slicer Main Window. | |
Inputs: Object (QObject), Event (QEvent) | |
""" | |
if event.type() == qt.QEvent.DragEnter: | |
self.dragEnterEvent(event) | |
return True | |
if event.type() == qt.QEvent.Drop: | |
self.dropEvent(event) | |
return True | |
return False | |
def dragEnterEvent(self, event): | |
""" | |
Actions to do when a drag enter event occurs in the Main Window. | |
Read up on https://doc.qt.io/qt-5.12/dnd.html#dropping | |
Input: Event (QEvent) | |
""" | |
event.ignore() | |
def dropEvent(self, event): | |
""" | |
Actions to do when an item is dropped onto the Main Window. | |
Read up on https://doc.qt.io/qt-5.12/dnd.html#dropping | |
Input: Event (QEvent) | |
""" | |
pass | |
event_manager = EventManager() | |
slicer.util.mainWindow().installEventFilter(event_manager) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment