#includeIn the above example, we have created a window using QMainWindow, and the rectangle is drawn in the paintEvent function. The QPainter object is initialized with the parent window, and the setBrush function sets the color of the brush to blue. Finally, the drawRect function is called with x, y, width, and height arguments to draw the rectangle. Thus, the QPainter function is part of the QT library.#include class Example : public QMainWindow { public: Example(QWidget *parent = nullptr) : QMainWindow(parent) { resize(300, 200); // set window size } void paintEvent(QPaintEvent *event) override { QPainter painter(this); painter.setBrush(QBrush(Qt::blue)); painter.drawRect(50, 50, 200, 100); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); Example window; window.show(); return app.exec(); }