-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomClass.py
More file actions
25 lines (19 loc) · 795 Bytes
/
customClass.py
File metadata and controls
25 lines (19 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from PyQt5.QtWidgets import QLabel
from PyQt5.QtGui import QPixmap
from PyQt5 import QtCore
class ImageArea(QLabel):
def __init__(self, parent):
super().__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasFormat("text/uri-list"):
event.acceptProposedAction()
def dropEvent(self, event) -> None:
text = event.mimeData().text()
if text.endswith(".png") or text.endswith(".jpg") or text.endswith(".jpeg"):
path = event.mimeData().urls()[0].toLocalFile()
pixmap = QPixmap(path)
width = self.width()
height = self.height()
pixmap = pixmap.scaled(width, height, QtCore.Qt.KeepAspectRatio)
self.setPixmap(pixmap)