mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-12-15 18:50:05 +01:00
Change icon used in Collapsible widget (#140)
* add ability to change icon * fix icon setting so it will load properly on start up * remove check on icon length. not necessary anymore * fix test * reduce duplicate code. expose _COLLAPSED and _EXPANDED to user on creation of QCollapsible widget * add ability to set icon with string or icon. * add tests for adding, setting icons * fix test. * fix test for icons * move file * fix test * remove hardcoded size. Use font size * add test docstring * fix test. chnage expanded/collapsed names * remove unnecessary strings * update example. add getter functions. remove lines. change function name * put default string in init. add getter tests * update test * cleanup typing and fix set setCollapsedIcon Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
"""A test module for testing collapsible"""
|
||||
|
||||
from qtpy.QtCore import QEasingCurve, Qt
|
||||
from qtpy.QtWidgets import QPushButton
|
||||
from qtpy.QtGui import QIcon
|
||||
from qtpy.QtWidgets import QPushButton, QStyle, QWidget
|
||||
|
||||
from superqt import QCollapsible
|
||||
|
||||
|
||||
def _get_builtin_icon(name: str) -> QIcon:
|
||||
"""Get a built-in icon from the Qt library."""
|
||||
widget = QWidget()
|
||||
try:
|
||||
pixmap = getattr(QStyle.StandardPixmap, f"SP_{name}")
|
||||
except AttributeError:
|
||||
pixmap = getattr(QStyle, f"SP_{name}")
|
||||
|
||||
return widget.style().standardIcon(pixmap)
|
||||
|
||||
|
||||
def test_checked_initialization(qtbot):
|
||||
"""Test simple collapsible"""
|
||||
wdg1 = QCollapsible("Advanced analysis")
|
||||
@@ -84,7 +96,7 @@ def test_changing_text(qtbot):
|
||||
wdg = QCollapsible()
|
||||
wdg.setText("Hi new text")
|
||||
assert wdg.text() == "Hi new text"
|
||||
assert wdg._toggle_btn.text() == QCollapsible._COLLAPSED + "Hi new text"
|
||||
assert wdg._toggle_btn.text() == "Hi new text"
|
||||
|
||||
|
||||
def test_toggle_signal(qtbot):
|
||||
@@ -98,3 +110,30 @@ def test_toggle_signal(qtbot):
|
||||
|
||||
with qtbot.waitSignal(wdg.toggled, timeout=500):
|
||||
wdg.collapse()
|
||||
|
||||
|
||||
def test_getting_icon(qtbot):
|
||||
"""Test setting string as toggle button."""
|
||||
wdg = QCollapsible("test")
|
||||
assert isinstance(wdg.expandedIcon(), QIcon)
|
||||
assert isinstance(wdg.collapsedIcon(), QIcon)
|
||||
|
||||
|
||||
def test_setting_icon(qtbot):
|
||||
"""Test setting icon for toggle button."""
|
||||
icon1 = _get_builtin_icon("ArrowRight")
|
||||
icon2 = _get_builtin_icon("ArrowDown")
|
||||
wdg = QCollapsible("test", expandedIcon=icon1, collapsedIcon=icon2)
|
||||
assert wdg._expanded_icon == icon1
|
||||
assert wdg._collapsed_icon == icon2
|
||||
|
||||
|
||||
def test_setting_symbol_icon(qtbot):
|
||||
"""Test setting string as toggle button."""
|
||||
wdg = QCollapsible("test")
|
||||
icon1 = wdg._convert_string_to_icon("+")
|
||||
icon2 = wdg._convert_string_to_icon("-")
|
||||
wdg.setCollapsedIcon(icon=icon1)
|
||||
assert wdg._collapsed_icon == icon1
|
||||
wdg.setExpandedIcon(icon=icon2)
|
||||
assert wdg._expanded_icon == icon2
|
||||
|
||||
Reference in New Issue
Block a user