截窗体、截主屏、截扩展屏

截窗体 

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)); // 按比例缩放

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页