I work at my homework in Qt Creator, where I paint to QWidget and I need to save some part of this QWdiget.
I tried to solve this problem:
QPixmap pixmap;
pixmap.copy(rectangle); // rectangle is part of QWidget, which I need to save
pixmap.save("example.png");
Thank you for help.
HTML & Script – Include the jQuery library. Create screenshot() function where initialize html2canvas on the body. By default, html2canvas set the image background color to black if save the screenshot. With the use of background: '#fff' set background white.
The QWidget class is the base class of all user interface objects. The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order.
You can use QWidget::render
for this. Assuming rectangle
is a QRect:
QPixmap pixmap(rectangle->size());
widget->render(&pixmap, QPoint(), QRegion(rectangle));
From QWidget::Grab:
QPixmap QWidget::grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With