Skip to content

ColorDialog

Qt Base Class: QColorDialog

Signature: QColorDialog(self, initial: Union[PySide6.QtGui.QColor, PySide6.QtGui.QRgba64, Any, PySide6.QtCore.Qt.GlobalColor, str, int], parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None QColorDialog(self, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None

Base classes

Name Children Inherits
DialogMixin
prettyqt.widgets.dialog
QColorDialog
PySide6.QtWidgets
QColorDialog(self, initial: Union[PySide6.QtGui.QColor, PySide6.QtGui.QRgba64, Any, PySide6.QtCore.Qt.GlobalColor, str, int], parent: Optional[PySide6.QtWidgets.QWidget] \= None) -> None

⋔ Inheritance diagram

graph TD
  1473296373008["widgets.ColorDialog"]
  1473296195376["widgets.DialogMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473241365200["QtWidgets.QColorDialog"]
  1473241356416["QtWidgets.QDialog"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473296195376 --> 1473296373008
  1473293688240 --> 1473296195376
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473241365200 --> 1473296373008
  1473241356416 --> 1473241365200
  1473290849680 --> 1473241356416
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: DialogMixin, QColorDialog

Dialog widget for specifying colors.

Source code in prettyqt\widgets\colordialog.py
class ColorDialog(widgets.DialogMixin, widgets.QColorDialog):
    """Dialog widget for specifying colors."""

    @classmethod
    def get_color(
        cls,
        preset: datatypes.ColorType = None,
        allow_alpha: bool = False,
        parent: widgets.QWidget | None = None,
    ) -> gui.Color:
        preset = colors.get_color(preset)
        kwargs = (
            dict(options=cls.ColorDialogOption.ShowAlphaChannel) if allow_alpha else {}
        )
        color = cls.getColor(preset, parent, **kwargs)  # type: ignore
        return gui.Color(color)

    def current_color(self) -> gui.Color:
        return gui.Color(self.currentColor())

    def get_qcolorshower(self) -> widgets.QWidget:
        return [
            a
            for a in self.children()
            if hasattr(a, "metaObject")
            and a.metaObject().className() == "QtPrivate::QColorShower"
        ][0]

    def get_qcolorshowlabel(self) -> widgets.QFrame:
        qcs = self.get_qcolorshower()
        return [
            b
            for b in qcs.children()
            if hasattr(b, "metaObject")
            and b.metaObject().className() == "QtPrivate::QColorShowLabel"
        ][0]

    def replace_qcolorshowlabel(self, widget: widgets.QWidget):
        # Find the dialog widget used to display the current
        # color, so we can replace it with our implementation
        qcs = self.get_qcolorshower()
        qcsl = self.get_qcolorshowlabel()
        qcs.layout().replaceWidget(qcsl, widget)
        # Make sure it doesn't receive signals while hidden
        qcsl.blockSignals(True)
        qcsl.hide()
        widget.show()

    def use_alpha_channel(self, value: bool = True):
        self.setOption(self.ColorDialogOption.ShowAlphaChannel, value)

    def hide_buttons(self, value: bool = True):
        self.setOption(self.ColorDialogOption.NoButtons, value)

    def use_native_dialog(self, value: bool = True):
        self.setOption(self.ColorDialogOption.DontUseNativeDialog, not value)

    @classmethod
    def get_custom_colors(cls) -> list[gui.Color]:
        return [gui.Color(cls.customColor(i)) for i in range(cls.customCount())]

    @classmethod
    def set_custom_colors(cls, colors_: list[datatypes.ColorType]):
        num = min(len(colors_), cls.customCount())
        for i in range(num):
            color = colors.get_color(colors_[i])
            cls.setCustomColor(i, color)

⌗ Property table

Qt Property Type Doc
objectName QString
modal bool
windowModality Qt::WindowModality
enabled bool
geometry QRect
frameGeometry QRect
normalGeometry QRect
x int
y int
pos QPoint
frameSize QSize
size QSize
width int
height int
rect QRect
childrenRect QRect
childrenRegion QRegion
sizePolicy QSizePolicy
minimumSize QSize
maximumSize QSize
minimumWidth int
minimumHeight int
maximumWidth int
maximumHeight int
sizeIncrement QSize
baseSize QSize
palette QPalette
font QFont
cursor QCursor
mouseTracking bool
tabletTracking bool
isActiveWindow bool
focusPolicy Qt::FocusPolicy
focus bool
contextMenuPolicy Qt::ContextMenuPolicy
updatesEnabled bool
visible bool
minimized bool
maximized bool
fullScreen bool
sizeHint QSize
minimumSizeHint QSize
acceptDrops bool
windowTitle QString
windowIcon QIcon
windowIconText QString
windowOpacity double
windowModified bool
toolTip QString
toolTipDuration int
statusTip QString
whatsThis QString
accessibleName QString
accessibleDescription QString
layoutDirection Qt::LayoutDirection
autoFillBackground bool
styleSheet QString
locale QLocale
windowFilePath QString
inputMethodHints QFlags
sizeGripEnabled bool
modal bool
currentColor QColor
options QFlags