[Development] how to get WinId of desktop in Qt6 without QDesktopWidget ?

Volker Hilsheimer volker.hilsheimer at qt.io
Wed Oct 7 10:38:19 CEST 2020


> On 7 Oct 2020, at 08:24, Martin Koller <kollix at aon.at> wrote:
> 
> Hi,
> 
> in Qt6 the QDesktopWidget is gone, which I used in
> 
>   QWidget *desktop = QApplication::desktop();
>   QPixmap pm = QGuiApplication::screenAt(event->globalPos())->
>                    grabWindow(desktop->winId(), event->globalPos().x(), event->globalPos().y(), 1, 1);
> 
> How do I get the desktop window id in Qt6 ?


You don’t need one, pass 0 for the WId into QScreen::grabWindow; it’s the default in Qt 6. Coordinates are then relative to your virtual desktop (or to the screen that you call grabWindow on if you don’t have a virtual desktop setup).

Volker



More information about the Development mailing list