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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
from PyQt5.QtCore import Qt, QSize, QRectF, QPoint
from PyQt5.QtGui import QBrush, QColor
from PyQt5.QtWidgets import QTableWidget, QMenu, QGraphicsRectItem
class streamTable(QTableWidget):
def __init__(self, int, int_, canvas=None, parent=None):
super(streamTable, self).__init__(int, int_, parent=parent)
self.canvas = canvas
def mousePressEvent(self, event):
if event.button() == Qt.RightButton:
point = event.pos()
col = self.getCol(point.x())
row = self.getRow(point.y())
menu = QMenu("Context Menu", self)
menu.addAction("Insert Column to right", lambda x=col: self.insertColRight(col))
menu.addAction("Insert Row to bottom", lambda x=point: self.insertRowBottom(row))
menu.exec_(self.mapToGlobal(point)+ QPoint(20, 25))
event.accept()
return super(streamTable, self).mousePressEvent(event)
# def mouseDoubleClickEvent(self):
# return super(streamTable, self).mouseDoubleClickEvent()
def getRow(self, point):
h = self.horizontalHeader().height()
i = 0
while (h < point):
h += self.rowHeight(i)
i += 1
return i
def getCol(self, point):
w = self.verticalHeader().width()
i = 0
while (w < point):
w += self.columnWidth(i)
i += 1
return i
def insertRowBottom(self, row):
self.insertRow(row + 1)
self.resize(self.sizeHint())
def insertColRight(self, col):
self.insertColumn(col + 1)
self.resize(self.sizeHint())
def resizeHandler(self):
self.resize(self.sizeHint())
# self.canvas.streamTableRect.setRect(streamTable.rect().adjusted(-10, -10, 10, 10))
def sizeHint(self):
w = self.verticalHeader().width() + 4
for i in range(self.columnCount()):
w += self.columnWidth(i)
h = self.horizontalHeader().height() + 4
for i in range(self.rowCount()):
h += self.rowHeight(i)
return QSize(w, h)
def rect(self):
w = self.verticalHeader().width() + 4
for i in range(self.columnCount()):
w += self.columnWidth(i)
h = self.horizontalHeader().height() + 4
for i in range(self.rowCount()):
h += self.rowHeight(i)
return QRectF(0, 0, w, h)
def cellEntered(self, row, column):
print(row, column)
class moveRect(QGraphicsRectItem):
def __init__(self, *args):
super(moveRect, self).__init__(*args)
self.setBrush(QBrush(QColor(0, 0, 0, 120)))
|