Add `SelectRect.delete()` for permanent scene dealloc

distribute_dis
Tyler Goodlet 2023-12-23 13:37:47 -05:00
parent a681b2f0bb
commit 263a5a8d07
1 changed files with 20 additions and 4 deletions

View File

@ -314,7 +314,6 @@ class SelectRect(QtWidgets.QGraphicsRectItem):
color.setAlpha(66) color.setAlpha(66)
self.setBrush(fn.mkBrush(color)) self.setBrush(fn.mkBrush(color))
self.setZValue(1e9) self.setZValue(1e9)
self.hide()
label = self._label = QLabel() label = self._label = QLabel()
label.setTextFormat(0) # markdown label.setTextFormat(0) # markdown
@ -343,6 +342,7 @@ class SelectRect(QtWidgets.QGraphicsRectItem):
] ]
self.add_to_view(viewbox) self.add_to_view(viewbox)
self.hide()
def add_to_view( def add_to_view(
self, self,
@ -579,10 +579,26 @@ class SelectRect(QtWidgets.QGraphicsRectItem):
) )
label.show() label.show()
def clear(self): def hide(self):
''' '''
Clear the selection box from view. Clear the selection box from its graphics scene but
don't delete it permanently.
''' '''
super().hide()
self._label.hide() self._label.hide()
self.hide()
# TODO: ensure noone else using dis.
clear = hide
def delete(self) -> None:
'''
De-allocate this rect from its rendering graphics scene.
Like a permanent hide.
'''
scen: QGraphicsScene = self.scene()
scen.removeItem(self)
if self._label:
scen.removeItem(self._label)