* enum combobox implementation * add enunm() * Update superqt/combobox/_enum_combobox.py Co-authored-by: Talley Lambert <talley.lambert@gmail.com> * add changes from review * updates from review * make current enum not raise exception from currentEnum * improve checks in setCurrentEnum * Update superqt/combobox/_tests/test_enum_comb_box.py Co-authored-by: Talley Lambert <talley.lambert@gmail.com> * fix test * fix test call * add class to top level __init__ * fix pre-commit mmissed call * rename * documentation first part * Update docs/combobox.md Co-authored-by: Talley Lambert <talley.lambert@gmail.com> * add possibility to use Optional[Enum] * add information about optional annotation * change type annotation to additional parameter * update docs * change to EnumMeta * add information about signal Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
1.6 KiB
ComboBox
Enum Combo Box
QEnumComboBox
is a variant of QComboBox
that populates the items in the combobox based on a python Enum
class. In addition to all
the methods provided by QComboBox
, this subclass adds the methods
enumClass
/setEnumClass
to get/set the current Enum
class represented by the combobox,
and currentEnum
/setCurrentEnum
to get/set the current Enum
member in the combobox.
There is also a new signal currentEnumChanged(enum)
analogous to currentIndexChanged
and currentTextChanged
.
Method like insertItem
and addItem
are blocked and try of its usage will end with RuntimeError
from enum import Enum
from superqt import QEnumComboBox
class SampleEnum(Enum):
first = 1
second = 2
third = 3
# as usual:
# you must create a QApplication before create a widget.
combo = QEnumComboBox()
combo.setEnumClass(SampleEnum)
other option is to use optional enum_class
argument of constructor and change
combo = QEnumComboBox()
combo.setEnumClass(SampleEnum)
to
combo = QEnumComboBox(enum_class=SampleEnum)
Allow None
QEnumComboBox
allow using Optional type annotation:
from enum import Enum
from superqt import QEnumComboBox
class SampleEnum(Enum):
first = 1
second = 2
third = 3
# as usual:
# you must create a QApplication before create a widget.
combo = QEnumComboBox()
combo.setEnumClass(SampleEnum, allow_none=True)
In this case there is added option ----
and currentEnum
will return None
for it.