Skip to content

QColorComboBox#

QComboBox designed to select from a specific set of colors.

from qtpy.QtWidgets import QApplication

from superqt import QColorComboBox

app = QApplication([])

colors = QColorComboBox()
colors.addColors(['red', 'green', 'blue'])

# show an "Add Color" item that opens a QColorDialog when clicked
colors.setUserColorsAllowed(True)

# emits a QColor when changed
colors.currentColorChanged.connect(print)
colors.show()

app.exec_()

QColorComboBox

Qt Class#

QComboBox

Signals#

currentColorChanged#

Enums#

QColorComboBox.InvalidColorPolicy#

  • Ignore

  • Warn

  • Raise

Methods#

A drop down menu for selecting colors.

Parameters:

Name Type Description Default
parent QWidget

The parent widget.

None
allow_user_colors bool

Whether to show an "Add Color" item that opens a QColorDialog when clicked. Whether the user can add custom colors by clicking the "Add Color" item. Default is False. Can also be set with setUserColorsAllowed.

False
add_color_text str

The text to display for the "Add Color" item. Default is "Add Color...".

'Add Color...'

addColor(color: Any) -> None #

Adds the color to the QComboBox.

addColors(colors: Sequence[Any]) -> None #

Adds colors to the QComboBox.

currentColor() -> QColor | None #

Returns the currently selected QColor or None if not yet selected.

currentColorName() -> str | None #

Returns the name of the currently selected QColor or black if None.

invalidColorPolicy() -> InvalidColorPolicy #

Returns the policy for handling invalid colors.

itemColor(index: int) -> QColor | None #

Returns the color of the item at the given index.

setCurrentColor(color: Any) -> None #

Adds the color to the QComboBox and selects it.

setInvalidColorPolicy(policy: InvalidColorPolicy | int | Literal['Raise', 'Ignore', 'Warn']) -> None #

Sets the policy for handling invalid colors.

setUserColorsAllowed(allow: bool) -> None #

Sets whether the user can add custom colors.

userColorsAllowed() -> bool #

Returns whether the user can add custom colors.