-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQLabelClickable.py
More file actions
59 lines (48 loc) · 1.82 KB
/
QLabelClickable.py
File metadata and controls
59 lines (48 loc) · 1.82 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
47
48
49
50
51
52
53
54
55
56
57
58
59
from Gate import Gate
from Util import Util
from enum import Enum
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5.QtWidgets import (QApplication, QGridLayout, QLabel, QMainWindow, QPushButton,
QLineEdit, QComboBox, QGroupBox, QTableView, QHeaderView, QHBoxLayout,
QFormLayout, QVBoxLayout, QDialog, QFileDialog, QAction)
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class QLabelClickable(QLabel):
gate = None
position = {'qbit':'-1', 'column':'-1'}
qbit = -1
clicked = pyqtSignal()
def __init__(self, gate, *args):
QLabel.__init__(self, *args)
self.setMaximumSize(50,50)
self.setScaledContents(True)
self.setAlignment(Qt.AlignCenter)
if type(gate) == type(Gate('x')):
self.gate = gate
else:
self.gate = Gate(gate)
def mouseReleaseEvent(self, event = None):
self.clicked.emit()
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.drag_start_position = event.pos()
def mouseMoveEvent(self, event : QtGui.QMouseEvent):
if not (event.buttons() & Qt.LeftButton):
return
if (event.pos() - self.drag_start_position).manhattanLength() < QApplication.startDragDistance():
return
pixmap = QPixmap(self.size())
drag = QDrag(self)
mimedata = QMimeData()
print(type(self.pixmap()))
print(type(None))
if(type(self.pixmap()) != type(None)):
mimedata.setImageData(self.pixmap().toImage())
drag.setMimeData(mimedata)
painter = QPainter(pixmap)
painter.drawPixmap(self.rect(), self.grab())
painter.end()
drag.setPixmap(pixmap)
drag.setHotSpot(event.pos())
drag.exec_(Qt.CopyAction | Qt.MoveAction)