// Getting the screenshot
// Here's one problem: Getting the current screen size (see note after code snippet).
// The QPixmap bg is the new background pixmap, containing screen and an overlay
painter.
setCompositionMode(QPainter::CompositionMode_SourceOver);
int x = 0;
int y = 0;
int w = screen.width();
int h = screen.height();
// Detecting if app is run on primary or secondary screen and adjust screenshot accordingly
if(globScreenRect.x() != 0) {
x = w-globScreenRect.width();
w = globScreenRect.width();
} else {
w = globScreenRect.width();
}
}
painter.drawPixmap(0, 0, overlay.width(), overlay.height(), screen,x,y,w,h);
painter.drawPixmap(overlay.rect(), overlay);
painter.end();
// Getting the screenshot
QPixmap screen = QPixmap::grabWindow(QApplication::desktop()->winId());
// Here's one problem: Getting the current screen size (see note after code snippet).
globScreenRect = QApplication::desktop()->screenGeometry();
// The QPixmap bg is the new background pixmap, containing screen and an overlay
QPainter painter(&bg);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
int x = 0;
int y = 0;
int w = screen.width();
int h = screen.height();
if(QApplication::desktop()->numScreens() == 2) {
// Detecting if app is run on primary or secondary screen and adjust screenshot accordingly
if(globScreenRect.x() != 0) {
x = w-globScreenRect.width();
w = globScreenRect.width();
} else {
w = globScreenRect.width();
}
}
painter.drawPixmap(0, 0, overlay.width(), overlay.height(), screen,x,y,w,h);
painter.drawPixmap(overlay.rect(), overlay);
painter.end();
To copy to clipboard, switch view to plain text mode
The problem seems to be detecting the current active screen size. "screenGeometry()" always returns the geometry of the primary screen (i.e. QRect(1024,0 1366x768) ). I could get the geometry of the secondary screen simply by using "screenGeometry(1)", but how do I know if the app is running on the primary or secondary screen?
Bookmarks