QColormapLineEdit¶
A QLineEdit that shows the colormap
named by its text, as you type: a swatch next to the name, or, if
fractional_colormap_width is more than 0.75, behind it. When the text isn't the
name of a colormap in the cmap catalog,
it shows a fallback colormap (gray, by default), and a question mark icon next to
the name (unless the swatch is behind it). It's the
line edit of QColormapComboBox and
CmapCatalogComboBox.
Requires cmap
Colormaps come from the cmap library,
which you can install with the cmap extra:
from qtpy.QtWidgets import QApplication
from superqt.cmap import QColormapLineEdit
app = QApplication([])
line_edit = QColormapLineEdit()
line_edit.setText("viridis")
line_edit.show()
app.exec()
With allow_invalid=False, text that isn't a colormap is replaced when editing
finishes: by the first completion of the line edit's completer, if it has one,
or else by the last valid colormap.
QColormapLineEdit
¶
QColormapLineEdit(
parent: QWidget | None = None,
*,
fractional_colormap_width: float = 0.35,
fallback_cmap: Colormap | str | None = "gray",
missing_icon: QIcon | StandardPixmap = MISSING,
checkerboard_size: int = 4,
allow_invalid: bool = True,
)
A QLineEdit that shows a colormap swatch.
When the current text is a valid colormap name from the cmap package, a swatch
of the colormap will be shown to the left of the text (if fractionalColormapWidth
is less than .75) or behind the text (for when the colormap fills the full width).
If the current text is not a valid colormap name, a swatch of the fallback colormap
will be shown instead (by default, a gray colormap) if fractionalColormapWidth is
less than .75.
Parameters:
-
parent(QWidget, default:None) –The parent widget.
-
fractional_colormap_width(float, default:0.35) –The fraction of the widget width to use for the colormap swatch. If the colormap is full width (greater than 0.75), the swatch will be drawn behind the text. Otherwise, the swatch will be drawn to the left of the text. Default is 0.33.
-
fallback_cmap(Colormap | str | None, default:'gray') –The colormap to use when the current text is not a recognized colormap. by default "gray".
-
missing_icon(QIcon | StandardPixmap, default:MISSING) –The icon to show when the current text is not a recognized colormap and
fractionalColormapWidthis less than .75. Default is a question mark. -
checkerboard_size(int, default:4) –Size (in pixels) of the checkerboard pattern to draw behind colormaps with transparency, by default 4. If 0, no checkerboard is drawn.
-
allow_invalid(bool, default:True) –If True, the user can enter any text, even if it does not represent a valid colormap (and
fallback_cmapwill be shown if it's invalid). If False, the text will be validated when editing is finished or focus is lost, and if the text is not a valid colormap, it will be reverted to the first available valid option from the completer, or, if that's not available, the last valid colormap. Default is True. This is only settable at initialization.
Subclass of QLineEdit
QColormapLineEdit inherits all of QLineEdit's methods, signals, and properties. Only those that superqt adds or changes are listed here.
Methods¶
A QLineEdit that shows a colormap swatch.
When the current text is a valid colormap name from the cmap package, a swatch
of the colormap will be shown to the left of the text (if fractionalColormapWidth
is less than .75) or behind the text (for when the colormap fills the full width).
If the current text is not a valid colormap name, a swatch of the fallback colormap
will be shown instead (by default, a gray colormap) if fractionalColormapWidth is
less than .75.
Parameters:
-
parent(QWidget, default:None) –The parent widget.
-
fractional_colormap_width(float, default:0.35) –The fraction of the widget width to use for the colormap swatch. If the colormap is full width (greater than 0.75), the swatch will be drawn behind the text. Otherwise, the swatch will be drawn to the left of the text. Default is 0.33.
-
fallback_cmap(Colormap | str | None, default:'gray') –The colormap to use when the current text is not a recognized colormap. by default "gray".
-
missing_icon(QIcon | StandardPixmap, default:MISSING) –The icon to show when the current text is not a recognized colormap and
fractionalColormapWidthis less than .75. Default is a question mark. -
checkerboard_size(int, default:4) –Size (in pixels) of the checkerboard pattern to draw behind colormaps with transparency, by default 4. If 0, no checkerboard is drawn.
-
allow_invalid(bool, default:True) –If True, the user can enter any text, even if it does not represent a valid colormap (and
fallback_cmapwill be shown if it's invalid). If False, the text will be validated when editing is finished or focus is lost, and if the text is not a valid colormap, it will be reverted to the first available valid option from the completer, or, if that's not available, the last valid colormap. Default is True. This is only settable at initialization.