Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt screenshot without start menu

Qt screenshot without start menu

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 711 Views
  • 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by ivanicy
    #1

    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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved