How do I set custom colours on a pyqt QColorDialog?

2.9k views Asked by At

I am bringing up a QcolorDialog like so:-

colour = QtGui.QColorDialog.getColor()

What I want to know is how to set the colours of the custom color swatches before I bring up the dialog. I have searched a lot and found the method setCustomColor() but I just can't get it to work. It repeatedly tells me

TypeError: argument 2 of QColorDialog.setCustomColor() has an invalid type

I have tried all manner of variations of how to create a QColor, but it never seems happy with it.This is what I am currently trying:-

mycolor = QtGui.QColor(0,0,0,0)
colour = QtGui.QColorDialog.setCustomColor(0,mycolor)

But it still gives me the same 'invalid type' error...

Any ideas?

1

There are 1 answers

1
Shadow9043 On BEST ANSWER

All you need to do is:

colour_dia = QtGui.QColorDialog()
mycolour = QtGui.QColor(0, 0, 0, 0).rgba()

#This needs a integer value for colour
colour_dia.setCustomColor(0, mycolour)

selected_colour = colour_dia.getColor()