Created
November 15, 2023 07:45
-
-
Save vadimpiven/ffb49929be96e031078e1d2e9e2d663c to your computer and use it in GitHub Desktop.
QMainWindow take high quality screenshot with transparency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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