ColorDialog
Base classes
| Name |
Children |
Inherits |
DialogMixin prettyqt.widgets.dialog
|
|
|
QColorDialog PySide6.QtWidgets QColorDialog(self, /, parent: PySide6.QtWidgets.QWidget | None \= None, *, currentColor: PySide6.QtGui.QColor | None \= None, options: PySide6.QtWidgets.QColorDialog.ColorDialogOption | None \= None) -> None |
|
|
⋔ Inheritance diagram
graph TD
62729059["widgets.ColorDialog"]
2345124717["widgets.DialogMixin"]
829357528["widgets.WidgetMixin"]
3227531497["core.ObjectMixin"]
2751680898["builtins.object"]
625385617["gui.PaintDeviceMixin"]
1010818720["QtWidgets.QColorDialog"]
392105360["QtWidgets.QDialog"]
3620195106["QtWidgets.QWidget"]
3984060476["QtCore.QObject"]
37984305["Shiboken.Object"]
673956333["QtGui.QPaintDevice"]
2345124717 --> 62729059
829357528 --> 2345124717
3227531497 --> 829357528
2751680898 --> 3227531497
625385617 --> 829357528
2751680898 --> 625385617
2751680898 --> 829357528
2751680898 --> 2345124717
1010818720 --> 62729059
392105360 --> 1010818720
3620195106 --> 392105360
3984060476 --> 3620195106
37984305 --> 3984060476
2751680898 --> 37984305
673956333 --> 3620195106
37984305 --> 673956333
🛈 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) -> QtCore.QObject:
return next(
a
for a in self.children()
if hasattr(a, "metaObject")
and a.metaObject().className() == "QtPrivate::QColorShower"
)
def get_qcolorshowlabel(self) -> QtCore.QObject:
qcs = self.get_qcolorshower()
return next(
b
for b in qcs.children()
if hasattr(b, "metaObject")
and b.metaObject().className() == "QtPrivate::QColorShowLabel"
)
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()
if not isinstance(qcs, widgets.QWidget) or not isinstance(qcsl, widgets.QWidget):
raise TypeError(qcs)
if (layout := qcs.layout()) is None:
raise RuntimeError(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)
|
:fa-brands-github: Show source on GitHub