Coverage for main/components/info_label.py: 87%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-03 15:51 +0000

1from PyQt6.QtCore import Qt 

2from PyQt6.QtWidgets import QToolTip, QLabel 

3 

4 

5class InfoLabel(QLabel): 

6 """A custom QLabel styled as an info icon that shows a tooltip on hover.""" 

7 

8 def __init__(self, text="", tooltip_text=""): 

9 """ 

10 Initialize the InfoLabel widget. 

11 

12 Args: 

13 text (str): The text to display inside the circular label (e.g., "i"). 

14 tooltip_text (str): The text to display when hovering over the label. 

15 """ 

16 super().__init__() 

17 

18 # Store the tooltip text for later use (shown on hover) 

19 self.tooltip_text = tooltip_text 

20 

21 # Store and display the main text (e.g., "i") 

22 self.text = text 

23 

24 # Define a fixed circular size for the label 

25 self.setFixedSize(25, 25) 

26 

27 # Apply a modern blue circular style with white text 

28 self.setStyleSheet(""" 

29 QLabel { 

30 border: 1px solid #3498db; /* Blue border */ 

31 border-radius: 12px; /* Rounded for circular shape */ 

32 background-color: #3498db; /* Blue background */ 

33 color: white; /* White text */ 

34 font-weight: bold; /* Bold for emphasis */ 

35 font-size: 12px; /* Compact, readable size */ 

36 } 

37 """) 

38 

39 # Set the text (e.g., "i" or "?") and center it in the label 

40 self.setText(self.text) 

41 self.setAlignment(Qt.AlignmentFlag.AlignCenter) 

42 

43 # Set the tooltip text for accessibility and hover feedback 

44 self.setToolTip(tooltip_text) 

45 

46 def enterEvent(self, event): 

47 """ 

48 Override the enter event to show a tooltip when the mouse hovers over the label. 

49 

50 Args: 

51 event (QEnterEvent): The Qt event triggered when the mouse enters the widget area. 

52 """ 

53 # Display the tooltip near the current mouse position 

54 QToolTip.showText(event.globalPosition().toPoint(), self.tooltip_text, self) 

55 

56 # Call the base implementation to preserve default behavior 

57 super().enterEvent(event)