#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; QPainter painter(&window); painter.drawLine(10, 10, 100, 100); window.show(); return app.exec(); }
#includeIn this example, we use the drawRect function to draw a rectangle on our QWidget. The parameters for drawRect include the coordinates for the top-left corner of the rectangle as well as the width and height. These examples use the Qt library package. Overall, the QPainter class is an essential part of building graphical interfaces using Qt.int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; QPainter painter(&window); painter.drawRect(20, 20, 100, 50); window.show(); return app.exec(); }