0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-12 18:51:50 +02:00

feat: add clickable label util

This commit is contained in:
2025-06-03 08:56:51 +02:00
committed by David Perl
parent 594912136e
commit 2dda58f7d2
5 changed files with 26 additions and 4 deletions

View File

@ -0,0 +1,13 @@
from __future__ import annotations
from PySide6.QtGui import QMouseEvent
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QLabel
class ClickableLabel(QLabel):
clicked = Signal()
def mouseReleaseEvent(self, ev: QMouseEvent) -> None:
self.clicked.emit()
return super().mouseReleaseEvent(ev)

View File

@ -14,6 +14,7 @@ from qtpy.QtWidgets import (
QWidget,
)
from bec_widgets.utils.clickable_label import ClickableLabel
from bec_widgets.utils.error_popups import SafeProperty, SafeSlot
@ -39,8 +40,8 @@ class ExpandableGroupFrame(QFrame):
self._title_layout = QHBoxLayout()
self._layout.addLayout(self._title_layout)
self._title = QLabel(f"<b>{title}</b>")
self._title_icon = QLabel()
self._title = ClickableLabel(f"<b>{title}</b>")
self._title_icon = ClickableLabel()
self._title_layout.addWidget(self._title_icon)
self._title_layout.addWidget(self._title)
self.icon_name = icon

View File

@ -2,7 +2,6 @@ import bec_qthemes
def pretty_display_theme(theme: str = "dark"):
print(f"loading theme {theme}")
palette = bec_qthemes.load_palette(theme)
foreground = palette.text().color().name()
background = palette.base().color().name()

View File

@ -65,6 +65,8 @@ class DeviceItem(ExpandableGroupFrame):
self.set_layout(layout)
self.adjustSize()
self._title.clicked.connect(self.switch_expanded_state)
self._title_icon.clicked.connect(self.switch_expanded_state)
@SafeSlot()
def switch_expanded_state(self):

View File

@ -77,7 +77,8 @@ def test_update_event_captured(device_browser, qtbot):
def test_device_item_expansion(device_browser, qtbot):
"""
Test that the form is displayed when the item is expanded
Test that the form is displayed when the item is expanded, and that the expansion is triggered
by clicking on the expansion button, the title, or the device icon
"""
device_item: QListWidgetItem = device_browser.ui.device_list.itemAt(0, 0)
widget: DeviceItem = device_browser.ui.device_list.itemWidget(device_item)
@ -90,6 +91,12 @@ def test_device_item_expansion(device_browser, qtbot):
qtbot.mouseClick(widget._expansion_button, Qt.MouseButton.LeftButton)
assert not widget.expanded
qtbot.mouseClick(widget._title, Qt.MouseButton.LeftButton)
qtbot.waitUntil(lambda: widget.expanded, timeout=500)
qtbot.mouseClick(widget._title_icon, Qt.MouseButton.LeftButton)
qtbot.waitUntil(lambda: not widget.expanded, timeout=500)
def test_device_item_mouse_press_and_move_events_creates_drag(device_browser, qtbot):
"""