-
Notifications
You must be signed in to change notification settings - Fork 4
/
dropImageLineEdit.py
55 lines (45 loc) · 2.11 KB
/
dropImageLineEdit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
/***************************************************************************
dropImageLineEdit
FSC QGIS plugin for biological recorders
-------------------
begin : 2014-02-17
copyright : (C) 2014 by Rich Burkmar, Field Studies Council
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import mimetypes
from PyQt5 import QtCore, QtGui, QtWidgets
class DragLineEdit(QtWidgets.QLineEdit):
imageDropped = QtCore.pyqtSignal(QtGui.QImage)
def __init__(self, parent):
QtWidgets.QLineEdit.__init__(self, parent)
self.setAcceptDrops (True)
def loadImage(self, data):
if isinstance(data, QtGui.QImage):
self.imageDropped.emit(data)
def dragEnterEvent (self, event):
mimedata = event.mimeData()
if mimedata.hasImage():
event.acceptProposedAction()
self.setBackColour(QtGui.QColor(125,255,125,255))
def dragLeaveEvent (self, event):
self.setBackColour(QtGui.QColor(0,0,0,0))
def setBackColour(self, colour):
p = self.palette()
p.setColor(self.backgroundRole(), colour)
self.setPalette(p)
def dropEvent(self, event):
self.setBackColour(QtGui.QColor(0,0,0,0))
mimedata = event.mimeData()
if mimedata.hasImage():
self.loadImage(mimedata.imageData())