from qtpy.QtGui import QBrush, QColor from qtpy.QtWidgets import QWidget # Create a QWidget widget = QWidget() # Create a QBrush with a solid blue color brush = QBrush(QColor(0, 0, 255)) # Set the background brush of the QWidget to the blue brush widget.setBackgroundbrush(brush)
from qtpy.QtGui import QBrush, QLinearGradient from qtpy.QtWidgets import QWidget # Create a QWidget widget = QWidget() # Create a linear gradient brush with two colors gradient = QLinearGradient(0, 0, 0, widget.height()) gradient.setColorAt(0, QColor(255, 255, 255)) gradient.setColorAt(1, QColor(0, 0, 0)) # Create a brush with the linear gradient brush = QBrush(gradient) # Set the background brush of the QWidget to the gradient brush widget.setBackgroundbrush(brush)In this example, we create a linear gradient brush using the QBrush class and the QLinearGradient class. We set the background of the QWidget to this gradient brush created. Package Library: QtGui