保存小部件的屏幕截图 [英] Save the screenshot of a widget

查看:51
本文介绍了保存小部件的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Qt 中保存一个小部件的屏幕截图.我创建了以下应该可以工作的代码:

I want to save a screenshot of a widget in Qt. I created the following code that should work:

  QWidget* activeWidget = getActiveWidget();//a function that returns the current widget.
  if (activeWidget == NULL)
  {
    return;
  }
  QPixmap screenshot;
  screenshot = QPixmap::grabWidget(activeWidget,activeWidget->rect());
  if(screenshot.isNull()){
    printf("ERROR");
  }
 bool a= screenshot.save("c:\\temp\\asd.jpg", "JPG", 50);

但不幸的是,这似乎不起作用.有谁知道是什么问题?

But unfortunately this does not seem to work. Does anyone know what the problem is?

推荐答案

这个答案这个论坛帖子,人们建议如下:

In this answer and this forum post, people suggest the following:

很可能,您的应用程序找不到处理 .jpg 文件所需的插件.要解决此问题,请执行以下操作之一:

Most likely, the plugin which is required to handle .jpg files is not found by your application. In order to resolve this issue, do one of the following things:

  • 如果您正在进行静态构建,请将 QTPLUGIN += qjpeg 添加到您的 .pro 文件或
  • 如果您正在进行动态构建,请将 %QTDIR%\plugins 中的 imageformats 文件夹放在您的 .exe 旁边
  • If you are doing a static build, add QTPLUGIN += qjpeg to your .pro file or
  • if you are doing a dynamic build, put the imageformats folder from %QTDIR%\plugins next to your .exe

这篇关于保存小部件的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆