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

Volker Hilsheimer volker.hilsheimer at qt.io
Wed Oct 14 23:36:22 CEST 2020


> On 7 Oct 2020, at 10:38, Volker Hilsheimer <volker.hilsheimer at qt.io> wrote:
> 
>> 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


Update: given that in Qt 6 QScreen provides equivalent functionality to QDesktopWidget (which is already gone in Qt 6) and QApplication::desktop(), we have now removed QApplication::desktop() from Qt 6.


Volker





More information about the Development mailing list