Qt版本5.12.0 QWidget *widget = QApplication::activeWindow(); QPixmap pixmap = QWidget::grab(QRect(0, 0, widget->width(), widget->height())); pixmap.save(QString("/data/screenshot.png"));