forked from PNL-MasonYu/WHAM_Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomWidgets.py
More file actions
46 lines (34 loc) · 1.23 KB
/
customWidgets.py
File metadata and controls
46 lines (34 loc) · 1.23 KB
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
from PyQt5 import Qt, QtWidgets, QtCore
class lineEditWithDragAndDrop(QtWidgets.QLineEdit):
def __init__(self, parent):
super().__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, e):
if e.mimeData().hasFormat('text/plain'):
e.accept()
elif e.mimeData().hasUrls:
e.accept()
else:
e.ignore()
def dropEvent(self, e):
if e.mimeData().hasFormat('text/plain'):
self.setText(e.mimeData().text())
elif e.mimeData().hasUrls:
url = e.mimeData().urls()[0].toLocalFile() # [0] means only the first file will get written
self.setText(url)
class user_friendly_QLineEdit(Qt.QLineEdit):
def __init__(self, parent):
super(user_friendly_QLineEdit, self).__init__(parent)
self.textChanged.connect(self.change_my_color)
self.returnPressed.connect(self.reset_my_color)
self.reset_my_color()
def change_my_color(self):
palette = Qt.QPalette()
palette.setColor(self.backgroundRole(), Qt.QColor('black'))
palette.setColor(self.foregroundRole(), Qt.QColor('white'))
self.setPalette(palette)
def reset_my_color(self):
palette = Qt.QPalette()
palette.setColor(self.backgroundRole(), Qt.QColor('white'))
palette.setColor(self.foregroundRole(), Qt.QColor('black'))
self.setPalette(palette)