Determine programmatically screens geometry in a multi-desktop environment with Qt

后端 未结 1 923
小鲜肉
小鲜肉 2021-01-21 14:39

I am writing a screenshotting app (a bit like puush) using Qt 4.8, and I am having troubles with multiple screens setups, especially when the main monitor (with coordinates

相关标签:
1条回答
  • 2021-01-21 15:13

    You can access each screen information inside the QDesktopWidget widget you are using and compute the overall rectangle for the snapshot.

    int screens = desktop->screenCount();
    QRect wholeDisplayGeometry;
    for (int i = 0; i < screens; ++i) {
         QRect screenRect = desktop->screen(i)->geometry();
         wholeDisplayGeometry = wholeDisplayGeometry.united(screenRect); //union
    }
    

    Now you can take the shot using the rectangle information:

    QPixmap shot = QPixmap::grabWindow (
        desktop->winId (), 
        wholeDisplayGeometry.x(), 
        wholeDisplayGeometry.y(), 
        wholeDisplayGeometry.width(), 
        wholeDisplayGeometry.height()
    );
    
    0 讨论(0)
提交回复
热议问题