#include#include int main(int argc, char *argv[]) { QApplication app(argc, argv); QPixmap pixmap(500, 500); // create a pixmap to draw on QPainter painter(&pixmap); // create a painter painter.fillRect(0, 0, 500, 500, Qt::white); // fill the pixmap with white color QRect rect(50, 50, 100, 100); // create a rectangle to erase painter.eraseRect(rect); // erase the rectangle pixmap.save("output.png"); // save the output return app.exec(); }
#includeIn this example, we create a QWidget object and set its size to 500x500 pixels. We then create a QPainter object and fill the widget with a white color. Finally, we create a QRect object that defines the rectangle we want to erase, and then call the QPainter eraseRect function to erase that rectangular area. Package library: Qt.#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget widget; // create a widget widget.resize(500, 500); // set the widget size QPainter painter(&widget); // create a painter painter.fillRect(0, 0, 500, 500, Qt::white); // fill the widget with white color QRect rect(50, 50, 100, 100); // create a rectangle to erase painter.eraseRect(rect); // erase the rectangle widget.show(); // show the widget return app.exec(); }