How to create screenshot of QWidget?

别说谁变了你拦得住时间么 提交于 2019-12-20 19:41:35

问题


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.


回答1:


You can use QWidget::render for this. Assuming rectangle is a QRect:

QPixmap pixmap(rectangle->size()); 
widget->render(&pixmap, QPoint(), QRegion(rectangle));



回答2:


From QWidget::Grab:

QPixmap QWidget::grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1)))


来源:https://stackoverflow.com/questions/10381854/how-to-create-screenshot-of-qwidget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!