相关资料:

https://blog.csdn.net/can3981132/article/details/51501235

将Qt的窗口显示的内容转化为图片的方法有两种:
第一种是调用QPixmap的静态成员函数
QPixmap grabWidget ( QWidget * widget, const QRect & rectangle )
将widget中的内容绘制到QPixmap中,  rectangle可以控制区域.
第二种方法是调用QWidget的函数
void render ( QPaintDevice * target, const QPoint & targetOffset = QPoint(), const QRegion & sourceRegion = QRegion(), RenderFlags renderFlags = RenderFlags( DrawWindowBackground | DrawChildren ) )
void render ( QPainter * painter, const QPoint & targetOffset = QPoint(), const QRegion & sourceRegion = QRegion(), RenderFlags renderFlags = RenderFlags( DrawWindowBackground | DrawChildren ) ) 
从参数可以看出接收绘制内容的是QPaintDevice,所以这里不仅限于QPixmap。

 1 Widget::Widget(QWidget *parent) :
 2 QWidget(parent),
 3 ui(new Ui::Widget)
 4 {
 5 ui->setupUi(this);
 6 // QPixmap pixmap(ui->tableWidget->size());
 7 // ui->tableWidget->render(&pixmap);
 8 QPixmap pixmap = QPixmap::grabWidget(ui->tableWidget);
 9 ui->label->setPixmap(pixmap);// 最后用一个label将pixmap显示出来
10 }

 


相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
  • 2021-10-29
  • 2022-01-12
猜你喜欢
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2021-06-21
相关资源
相似解决方案