简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM