Skip to content

Instantly share code, notes, and snippets.

@vadimpiven
Created November 15, 2023 07:45
Show Gist options
  • Save vadimpiven/ffb49929be96e031078e1d2e9e2d663c to your computer and use it in GitHub Desktop.
Save vadimpiven/ffb49929be96e031078e1d2e9e2d663c to your computer and use it in GitHub Desktop.
QMainWindow take high quality screenshot with transparency
// SPDX-License-Identifier: CC0-1.0
// Creative Commons Zero v1.0 Universal License: https://creativecommons.org/publicdomain/zero/1.0/deed
void MainWindow::takeScreenshot()
{
assert(isVisible() || !"call show() before taking screenshot");
QPixmap pixmap(size() * devicePixelRatioF());
pixmap.setDevicePixelRatio(devicePixelRatioF());
pixmap.fill(Qt::transparent);
render(&pixmap);
pixmap.save("screenshot.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment