Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Qt screenshot without start menu

    General and Desktop
    2
    2
    573
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ivanicy
      ivanicy last edited by ivanicy

      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

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by

        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");
        }
        
        1 Reply Last reply Reply Quote 3
        • First post
          Last post