Hi guys,

I've got a little problem: A little app of mine has a screenshot of the current desktop set as background. The application always runs in fullscreen. It all works just perfectly on a single monitor. However, on a dual-head system I run into some problems getting the right part of the screenshot to be set as background.

More details: I've got my primary monitor on the right and a secondary monitor on the left. I simply cannot detect reliably what screen I'm running the app on or what global position the app has. Some code:

Qt Code:
  1. // Getting the screenshot
  2. QPixmap screen = QPixmap::grabWindow(QApplication::desktop()->winId());
  3.  
  4. // Here's one problem: Getting the current screen size (see note after code snippet).
  5. globScreenRect = QApplication::desktop()->screenGeometry();
  6.  
  7. // The QPixmap bg is the new background pixmap, containing screen and an overlay
  8. QPainter painter(&bg);
  9. painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
  10. int x = 0;
  11. int y = 0;
  12. int w = screen.width();
  13. int h = screen.height();
  14. if(QApplication::desktop()->numScreens() == 2) {
  15. // Detecting if app is run on primary or secondary screen and adjust screenshot accordingly
  16. if(globScreenRect.x() != 0) {
  17. x = w-globScreenRect.width();
  18. w = globScreenRect.width();
  19. } else {
  20. w = globScreenRect.width();
  21. }
  22.  
  23. }
  24. painter.drawPixmap(0, 0, overlay.width(), overlay.height(), screen,x,y,w,h);
  25. painter.drawPixmap(overlay.rect(), overlay);
  26. 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?

If I try to find out the current global position of the app by "this->pos().x()" or even "mapToGlobal(this->pos()).x()", it always gives me "0", i.e. the absolute top left position... According to the Qt Doc: "mapToGlobal - Translates the widget coordinate pos to global screen coordinates.", but it somehow doesn't do that...?

Am thankful for any help

huilui