From e3efc5ff769f0041e852be2ffd655e6a1586fb87 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Fri, 20 May 2022 15:59:11 +0800 Subject: [PATCH] fix: get screenshot fail on windows --- DSView/pv/mainwindow.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 0e40bb3d..9b29ccc3 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -36,15 +36,15 @@ #include #include #include -#include #include #include #include #include #include - -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include + +#ifdef _WIN32 +#include #endif #include "mainwindow.h" @@ -886,15 +886,18 @@ void MainWindow::on_screenShot() AppConfig &app = AppConfig::Instance(); QString default_name = app._userHistory.screenShotPath + "/" + APP_NAME + QDateTime::currentDateTime().toString("-yyMMdd-hhmmss"); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QScreen *scr = QGuiApplication::primaryScreen(); - QPixmap pixmap = scr->grabWindow(winId()); +#ifdef _WIN32 + int x = parentWidget()->pos().x(); + int y = parentWidget()->pos().y(); + int w = parentWidget()->frameGeometry().width(); + int h = parentWidget()->frameGeometry().height(); + QDesktopWidget *desktop = QApplication::desktop(); + QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(desktop->winId(), x, y, w, h); #else - QPixmap pixmap = QPixmap::grabWindow(winId()); + QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(winId()); #endif - + QString format = "png"; - QString fileName = QFileDialog::getSaveFileName( this, tr("Save As"),