Skip to content

Commit dc28d25

Browse files
fix overlay disable bounding box calculation to remove artefacts and force re-draws
1 parent 66e1fc3 commit dc28d25

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

NodeGraphQt/qgraphics/node_overlay_disabled.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python
2-
from Qt import QtGui, QtCore, QtWidgets
2+
from Qt import QtCore, QtGui, QtWidgets
33

44
from NodeGraphQt.constants import Z_VAL_NODE_WIDGET
55

@@ -22,7 +22,17 @@ def __init__(self, parent=None, text=None):
2222
self.text = text
2323

2424
def boundingRect(self):
25-
return self.parentItem().boundingRect()
25+
rect = self.parentItem().boundingRect()
26+
27+
# marging (base margin = 20, point size = 4, pen width bleed = 4)
28+
margin = 28
29+
30+
return QtCore.QRectF(
31+
rect.left() - margin / 2,
32+
rect.top() - margin / 2,
33+
rect.width() + margin,
34+
rect.height() + margin,
35+
)
2636

2737
def paint(self, painter, option, widget):
2838
"""
@@ -37,11 +47,14 @@ def paint(self, painter, option, widget):
3747
painter.save()
3848

3949
margin = 20
40-
rect = self.boundingRect()
41-
dis_rect = QtCore.QRectF(rect.left() - (margin / 2),
42-
rect.top() - (margin / 2),
43-
rect.width() + margin,
44-
rect.height() + margin)
50+
rect = self.parentItem().boundingRect()
51+
dis_rect = QtCore.QRectF(
52+
rect.left() - (margin / 2),
53+
rect.top() - (margin / 2),
54+
rect.width() + margin,
55+
rect.height() + margin,
56+
)
57+
4558
if not self.proxy_mode:
4659
pen = QtGui.QPen(QtGui.QColor(*self.color), 8)
4760
pen.setCapStyle(QtCore.Qt.RoundCap)
@@ -52,10 +65,12 @@ def paint(self, painter, option, widget):
5265
bg_color = QtGui.QColor(*self.color)
5366
bg_color.setAlpha(100)
5467
bg_margin = -0.5
55-
bg_rect = QtCore.QRectF(dis_rect.left() - (bg_margin / 2),
56-
dis_rect.top() - (bg_margin / 2),
57-
dis_rect.width() + bg_margin,
58-
dis_rect.height() + bg_margin)
68+
bg_rect = QtCore.QRectF(
69+
dis_rect.left() - (bg_margin / 2),
70+
dis_rect.top() - (bg_margin / 2),
71+
dis_rect.width() + bg_margin,
72+
dis_rect.height() + bg_margin,
73+
)
5974
painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0)))
6075
painter.setBrush(bg_color)
6176
painter.drawRoundedRect(bg_rect, 5, 5)
@@ -71,14 +86,17 @@ def paint(self, painter, option, widget):
7186
painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight())
7287
painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft())
7388

74-
point_pos = (dis_rect.topLeft(), dis_rect.topRight(),
75-
dis_rect.bottomLeft(), dis_rect.bottomRight())
89+
point_pos = (
90+
dis_rect.topLeft(),
91+
dis_rect.topRight(),
92+
dis_rect.bottomLeft(),
93+
dis_rect.bottomRight(),
94+
)
7695
painter.setBrush(QtGui.QColor(255, 0, 0, 255))
7796
for p in point_pos:
7897
p.setX(p.x() - (point_size / 2))
7998
p.setY(p.y() - (point_size / 2))
80-
point_rect = QtCore.QRectF(
81-
p, QtCore.QSizeF(point_size, point_size))
99+
point_rect = QtCore.QRectF(p, QtCore.QSizeF(point_size, point_size))
82100
painter.drawEllipse(point_rect)
83101

84102
if self.text and not self.proxy_mode:
@@ -91,16 +109,22 @@ def paint(self, painter, option, widget):
91109
font_height = font_metrics.height()
92110
txt_w = font_width * 1.25
93111
txt_h = font_height * 2.25
94-
text_bg_rect = QtCore.QRectF((rect.width() / 2) - (txt_w / 2),
95-
(rect.height() / 2) - (txt_h / 2),
96-
txt_w, txt_h)
112+
text_bg_rect = QtCore.QRectF(
113+
(rect.width() / 2) - (txt_w / 2),
114+
(rect.height() / 2) - (txt_h / 2),
115+
txt_w,
116+
txt_h,
117+
)
97118
painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 0.5))
98119
painter.setBrush(QtGui.QColor(*self.color))
99120
painter.drawRoundedRect(text_bg_rect, 2, 2)
100121

101-
text_rect = QtCore.QRectF((rect.width() / 2) - (font_width / 2),
102-
(rect.height() / 2) - (font_height / 2),
103-
txt_w * 2, font_height * 2)
122+
text_rect = QtCore.QRectF(
123+
(rect.width() / 2) - (font_width / 2),
124+
(rect.height() / 2) - (font_height / 2),
125+
txt_w * 2,
126+
font_height * 2,
127+
)
104128

105129
painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 1))
106130
painter.drawText(text_rect, self.text)

0 commit comments

Comments
 (0)