QPainter painter; QBrush brush(Qt::red); painter.setBrush(brush); painter.drawRect(10, 10, 100, 100);
QPainter painter; QLinearGradient gradient(0, 0, 200, 200); gradient.setColorAt(0.0, Qt::yellow); gradient.setColorAt(1.0, Qt::blue); QBrush brush(gradient); painter.setBrush(brush); painter.drawRect(10, 10, 100, 100);In both examples, the QPainter brush is used to set the fill pattern or color of the rectangle, and the resulting effect is achieved by calling the `setBrush` method of the QPainter object. These examples demonstrate how the QPainter brush can be used to create a variety of fill patterns and colors, and can be used in combination with other QPainter classes to create complex graphical elements. The QPainter brush is a part of the Qt GUI library, which is a popular C++ framework for creating graphical user interfaces. It is included with the Qt package, which provides a comprehensive set of classes and tools for developing cross-platform applications.