QColormapComboBox#
QComboBox
variant to select from a specific set of colormaps.
requires cmap
This widget uses the cmap library to provide colormaps. You can install it with:
# use the `cmap` extra to include colormap support
pip install superqt[cmap]
ColorMapLike objects#
Colormaps may be specified in a variety of ways, such as by name (string), an iterable of a color/color-like objects, or as
a cmap.Colormap
instance. See cmap documentation for details on
all ColormapLike types
Example#
from cmap import Colormap
from qtpy.QtWidgets import QApplication
from superqt import QColormapComboBox
app = QApplication([])
cmap_combo = QColormapComboBox()
# see note above about colormap-like objects
# as names from the cmap catalog
cmap_combo.addColormaps(["viridis", "plasma", "magma", "gray"])
# as a sequence of colors, linearly interpolated
cmap_combo.addColormap(("#0f0", "slateblue", "#F3A003A0"))
# as a `cmap.Colormap` instance with custom name:
cmap_combo.addColormap(Colormap(("green", "white", "orange"), name="MyMap"))
cmap_combo.show()
app.exec()
Style Customization#
Note that both the LineEdit and the dropdown can be styled to have the colormap on the left, or fill the entire width of the widget.
To make the CombBox label colormap fill the entire width of the widget:
from superqt.cmap import QColormapLineEdit
cmap_combo.setLineEdit(QColormapLineEdit())
To make the CombBox dropdown colormaps fill less than the entire width of the widget:
from superqt.cmap import QColormapItemDelegate
delegate = QColormapItemDelegate(fractional_colormap_width=0.33)
cmap_combo.setItemDelegate(delegate)
Qt Class#
Signals#
currentColormapChanged
#
Methods#
A drop down menu for selecting colors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
QWidget
|
The parent widget. |
None
|
allow_user_colormaps |
bool
|
Whether the user can add custom colormaps by clicking the "Add
Colormap..." item. Default is False. Can also be set with
|
False
|
add_colormap_text |
str
|
The text to display for the "Add Colormap..." item. Default is "Add Colormap...". |
'Add Colormap...'
|
addColormap(cmap: ColorStopsLike) -> None
#
Adds the colormap to the QComboBox.
addColormaps(colors: Sequence[Any]) -> None
#
Adds colors to the QComboBox.
currentColormap() -> Colormap | None
#
Returns the currently selected Colormap or None if not yet selected.
itemColormap(index: int) -> Colormap | None
#
Returns the color of the item at the given index.
setCurrentColormap(color: Any) -> None
#
Adds the color to the QComboBox and selects it.
setUserAdditionsAllowed(allow: bool) -> None
#
Sets whether the user can add custom colors.
If enabled, an "Add Colormap..." item will be added to the end of the list. When clicked, a dialog will be shown to allow the user to select a colormap from the cmap catalog.
userAdditionsAllowed() -> bool
#
Returns whether the user can add custom colors.