tobspr tobspr - 1 year ago 78
Python Question

Check if QColorDialog got cancelled

I'm using a

in PyQt5 to let the user select a color. My code looks like this:

result = QColorDialog.getColor(QColor(,,,, =,,

This works fine so far, however I am unable to detect whether the user cancelled the dialog.

Even when the dialog is canceled, the returned color is
QColor(0, 0, 0, 255)
, and not
, as expected.

Is there a way to detect whether the dialog got canceled using the static
method? Or do I have to manually construct a

Answer Source

Use QColor::isValid to check if the color returned is a valid color.