components.info_label
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)
class
InfoLabel(PyQt6.QtWidgets.QLabel):
6class InfoLabel(QLabel): 7 """A custom QLabel styled as an info icon that shows a tooltip on hover.""" 8 9 def __init__(self, text="", tooltip_text=""): 10 """ 11 Initialize the InfoLabel widget. 12 13 Args: 14 text (str): The text to display inside the circular label (e.g., "i"). 15 tooltip_text (str): The text to display when hovering over the label. 16 """ 17 super().__init__() 18 19 # Store the tooltip text for later use (shown on hover) 20 self.tooltip_text = tooltip_text 21 22 # Store and display the main text (e.g., "i") 23 self.text = text 24 25 # Define a fixed circular size for the label 26 self.setFixedSize(25, 25) 27 28 # Apply a modern blue circular style with white text 29 self.setStyleSheet(""" 30 QLabel { 31 border: 1px solid #3498db; /* Blue border */ 32 border-radius: 12px; /* Rounded for circular shape */ 33 background-color: #3498db; /* Blue background */ 34 color: white; /* White text */ 35 font-weight: bold; /* Bold for emphasis */ 36 font-size: 12px; /* Compact, readable size */ 37 } 38 """) 39 40 # Set the text (e.g., "i" or "?") and center it in the label 41 self.setText(self.text) 42 self.setAlignment(Qt.AlignmentFlag.AlignCenter) 43 44 # Set the tooltip text for accessibility and hover feedback 45 self.setToolTip(tooltip_text) 46 47 def enterEvent(self, event): 48 """ 49 Override the enter event to show a tooltip when the mouse hovers over the label. 50 51 Args: 52 event (QEnterEvent): The Qt event triggered when the mouse enters the widget area. 53 """ 54 # Display the tooltip near the current mouse position 55 QToolTip.showText(event.globalPosition().toPoint(), self.tooltip_text, self) 56 57 # Call the base implementation to preserve default behavior 58 super().enterEvent(event)
A custom QLabel styled as an info icon that shows a tooltip on hover.
InfoLabel(text='', tooltip_text='')
9 def __init__(self, text="", tooltip_text=""): 10 """ 11 Initialize the InfoLabel widget. 12 13 Args: 14 text (str): The text to display inside the circular label (e.g., "i"). 15 tooltip_text (str): The text to display when hovering over the label. 16 """ 17 super().__init__() 18 19 # Store the tooltip text for later use (shown on hover) 20 self.tooltip_text = tooltip_text 21 22 # Store and display the main text (e.g., "i") 23 self.text = text 24 25 # Define a fixed circular size for the label 26 self.setFixedSize(25, 25) 27 28 # Apply a modern blue circular style with white text 29 self.setStyleSheet(""" 30 QLabel { 31 border: 1px solid #3498db; /* Blue border */ 32 border-radius: 12px; /* Rounded for circular shape */ 33 background-color: #3498db; /* Blue background */ 34 color: white; /* White text */ 35 font-weight: bold; /* Bold for emphasis */ 36 font-size: 12px; /* Compact, readable size */ 37 } 38 """) 39 40 # Set the text (e.g., "i" or "?") and center it in the label 41 self.setText(self.text) 42 self.setAlignment(Qt.AlignmentFlag.AlignCenter) 43 44 # Set the tooltip text for accessibility and hover feedback 45 self.setToolTip(tooltip_text)
Initialize the InfoLabel widget.
Args: text (str): The text to display inside the circular label (e.g., "i"). tooltip_text (str): The text to display when hovering over the label.
def
enterEvent(self, event):
47 def enterEvent(self, event): 48 """ 49 Override the enter event to show a tooltip when the mouse hovers over the label. 50 51 Args: 52 event (QEnterEvent): The Qt event triggered when the mouse enters the widget area. 53 """ 54 # Display the tooltip near the current mouse position 55 QToolTip.showText(event.globalPosition().toPoint(), self.tooltip_text, self) 56 57 # Call the base implementation to preserve default behavior 58 super().enterEvent(event)
Override the enter event to show a tooltip when the mouse hovers over the label.
Args: event (QEnterEvent): The Qt event triggered when the mouse enters the widget area.