#include#include void MyWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.drawLine(10, 10, 70, 10); }
#include#include void MyWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); QLinearGradient gradient(0, 0, 100, 100); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, Qt::black); painter.setBrush(gradient); painter.drawRect(10, 10, 80, 60); }
#includeThe package library for QPainter is Qt, which is a comprehensive C++ GUI toolkit that includes a wide range of classes and tools for developing cross-platform applications with a native look and feel. QPainter is just one of many useful classes in the Qt library that can help you create powerful and attractive GUI applications with ease.#include void createImage() { QImage image(100, 100, QImage::Format_RGB32); QPainter painter(&image); painter.fillRect(0, 0, 100, 100, Qt::white); painter.drawLine(10, 10, 90, 90); painter.drawLine(10, 90, 90, 10); image.save("myimage.png"); }