from PySide.QtGui import QBrush, QColor # create a brush with a solid color brush = QBrush(QColor(255, 0, 0)) # use the brush to render a rectangle painter.fillRect(10, 10, 100, 100, brush)
from PySide.QtGui import QBrush, QLinearGradient # create a gradient brush gradient = QLinearGradient(0, 0, 100, 100) gradient.setColorAt(0, QColor(255, 0, 0)) gradient.setColorAt(1, QColor(0, 0, 255)) brush = QBrush(gradient) # use the brush to render a rectangle painter.fillRect(10, 10, 100, 100, brush)This code creates a QBrush object with a linear gradient that goes from red to blue and uses it to fill a rectangle with dimensions 100x100 starting at the point (10, 10). The result is a rectangle with a gradient fill. In conclusion, these code examples use the PySide QtGui package library to create and use QBrush objects for solid color or gradient fills.