Qt screenshot without start menu
Unsolved
General and Desktop
-
Hello!
I am trying to get a screenshot of my application, but I don't want the start menu. Do you know how to get this screenshot without the start menu?
Here is my code:
QScreen *screen = QGuiApplication::primaryScreen(); if (const QWindow *window = windowHandle()) screen = window->screen(); if (!screen) { return; } QPixmap originalPixmap = screen->grabWindow(0); QApplication::clipboard()->setPixmap(originalPixmap, QClipboard::Clipboard); QIcon icon2(":/ThermalAnalysis/Resources/ThermalAnalysis/screenshot.png"); icon2.addPixmap(QPixmap(":/ThermalAnalysis/Resources/ThermalAnalysis/screenshot.png")); ui->screenshotButton->setIcon(icon2); QMessageBox::information(NULL, "Screenshot", "Screenshot sent to clipboard.", QMessageBox::Ok);
Thank you very much
-
Hi! You can use QWidget::grab() to grab only the widget you're interested in. E.g., to grab the central widget of a
QMainWindow
, use something like this:void MainWindow::on_pushButton_clicked() { auto const pm = centralWidget()->grab(); pm.save("/path/to/file.png"); }