Save the screenshot of a widget

最后都变了- 提交于 2019-12-20 07:17:10

问题


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?


回答1:


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

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:

  • 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


来源:https://stackoverflow.com/questions/11930201/save-the-screenshot-of-a-widget

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