from qtpy.QtGui import QColor from qtpy.QtWidgets import QWidget widget = QWidget() widget.setAutoFillBackground(True) color = QColor(100, 100, 200) palette = widget.palette() palette.setColor(widget.backgroundRole(), color) widget.setPalette(palette)
from qtpy.QtGui import QColor color = QColor(100, 100, 200) hex_value = color.name() print(hex_value)In this example, a QColor object is created with an RGB color of (100, 100, 200). The color's hexadecimal representation is then retrieved using the name method and printed to the console. Package library: QtPy