D_G
D_G

Reputation: 25

How do I set custom colours on a pyqt QColorDialog?

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?

Upvotes: 1

Views: 3127

Answers (1)

Shadow9043
Shadow9043

Reputation: 2260

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()

Upvotes: 2

Related Questions