# set a red background color brush = QtGui.QBrush(QtCore.Qt.red)
# set a gradient background color gradient = QtGui.QLinearGradient() gradient.setColorAt(0, QtCore.Qt.blue) gradient.setColorAt(1, QtCore.Qt.green) brush = QtGui.QBrush(gradient)
# set a pattern background color image = QtGui.QImage('pattern.png') brush = QtGui.QBrush(image) brush.setStyle(QtCore.Qt.TexturePattern)In these examples, QBrush is used to set different types of background colors. The first example sets a solid red color, the second example sets a gradient color between blue and green, and the third example sets a pattern from an image file. The package library used for these examples is PyQt4.QtGui.