问题
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