Skip to content

Commit

Permalink
Fix some issues with the hover label
Browse files Browse the repository at this point in the history
Improve the parent system.
Don't reach up to the grandparent.
  • Loading branch information
gentlegiantJGC committed May 17, 2024
1 parent 70465a4 commit 0a498a3
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/amulet_editor/models/widgets/_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def _elide_text(self, text: str) -> str:

class QHoverLabel(QLabel):
def __init__(self, text: str, parent: QWidget):
super().__init__(parent)
super().__init__(parent.window())

self._parent = parent

self.shadow = QGraphicsDropShadowEffect(self)
self.shadow.setBlurRadius(7)
Expand All @@ -146,28 +148,23 @@ def __init__(self, text: str, parent: QWidget):
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setGraphicsEffect(self.shadow)
self.setObjectName("hover_label")
self.setParent(self.window())
self.setText(text)

def setText(self, text: str) -> None:
super().setText(text)
self.setFixedSize(self.minimumSizeHint() + QSize(30, 6))

def showEvent(self, event: QShowEvent) -> None:
parent = self.parent()
assert isinstance(parent, QWidget)
# TODO: do we need the grandparent?
grandparent = parent.parent()
assert isinstance(grandparent, QWidget)
pos_gbl = grandparent.mapToGlobal(parent.pos())
pos_rel = parent.mapFromGlobal(pos_gbl)
window = self.parentWidget()
parent = self._parent
pos_gbl = parent.mapToGlobal(QPoint(0, 0))
pos_rel = window.mapFromGlobal(pos_gbl)
pos_mov = QPoint(
pos_rel.x() + parent.width() + 3,
pos_rel.y() + (parent.height() - self.height()) // 2,
)
self.move(pos_mov)

parent.update() # Fix rendering artifacts
return super().showEvent(event)

def hideEvent(self, event: QHideEvent) -> None:
Expand Down

0 comments on commit 0a498a3

Please sign in to comment.