一、环境介绍
QT : 5.12.6
操作系统: win10 x64
编译器: MinGW32
二、示例代码头文件
#include
#include
connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
timer.start(50);
2.1 截取全屏保存为图片
void Form::update()
{
static int cnt=0;
QScreen *screen = QGuiApplication::primaryScreen();
//截取当前桌面全屏画面
screen->grabWindow(0).save(QString("%1.jpg").arg(cnt++));
}
2.2 截取窗口指定位置保存图片
void Form::update()
{
static int cnt=0;
QScreen *screen = QGuiApplication::primaryScreen();