from PyQt5.QtGui import QColor # Create a QColor instance with RGBA values color = QColor.fromRgbF(0.5, 0.5, 0.5, 1.0) # Print the color values as tuple print(color.getRgbF()) # (0.5, 0.5, 0.5, 1.0)
from PyQt5.QtGui import QLinearGradient, QColor # Create a linear gradient object gradient = QLinearGradient(0, 0, 100, 100) # Add QColor instances to the gradient gradient.setColorAt(0.0, QColor.fromRgbF(1.0, 1.0, 1.0, 1.0)) gradient.setColorAt(0.5, QColor.fromRgbF(0.5, 0.5, 0.5, 1.0)) gradient.setColorAt(1.0, QColor.fromRgbF(0.0, 0.0, 0.0, 1.0))In this example, we create a QLinearGradient object that represents a linear gradient. We add three different QColor instances to the gradient with different RGB and alpha values using the setColorAt method. The result is a gradient that goes from white to black. In conclusion, we can use the PyQt5.QtGui QColor class to represent colors in the RGB color space. We can create QColor instances using several methods, including the fromRgbF method. We can then use these QColor instances in different ways, such as creating gradients or painting objects on a canvas.