截窗体
QPixmap map=this->grab();
截主屏
QScreen *screen=QGuiApplication::primaryScreen();
QPixmap map=screen->grabWindow(0);
截扩展屏
QRect r2 = QApplication::desktop()->screenGeometry(1);
QPixmap map=QPixmap::grabWindow(QApplication::desktop()->winId(),r2.left(),r2.top(),r2.width(),r2.height());
QPixmap转label显示
ui->lblScreen->setPixmap(map.scaled(ui->lblScreen->width(),ui->lblScreen->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); // 按比例缩放