Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues with the hover label #82

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading