from PyQt4 import QtGui app = QtGui.QApplication([]) color = QtGui.QColorDialog.getColor() if color.isValid(): print('Selected color:', color.name())
from PyQt4 import QtGui app = QtGui.QApplication([]) dialog = QtGui.QColorDialog() dialog.setOption(QtGui.QColorDialog.ShowAlphaChannel, True) if dialog.exec_() == QtGui.QDialog.Accepted: color = dialog.selectedColor() print('Selected color:', color.name())In this example, a QColorDialog object is created and customized using setOption(). The ShowAlphaChannel option is set to True, which allows the user to select colors with transparency. The exec_() method opens the dialog and returns whether the user accepted or rejected the color selection. If the user accepted, the selected color is obtained using selectedColor() and its name is printed to the console. These examples show how QColorDialog can be used in PyQt4 to add color selection capabilities to desktop applications.