[Interest] High-dpi fixing for Qt 5.5

Martins, Sérgio sergio.martins at kdab.com
Fri Mar 2 16:26:03 CET 2018

On 2018-03-02 15:21, Elvis Stansvik wrote:
> 2018-03-02 16:18 GMT+01:00 Elvis Stansvik <elvstone at gmail.com>:
>> 2018-03-02 15:54 GMT+01:00 Nikos Chantziaras <realnc at gmail.com>:
>>> On 02/03/18 16:37, Elvis Stansvik wrote:
>>>> [...]
>>>> How can I (as application developer) get notified of screen changes 
>>>> of
>>>> non-QWindow-backed widgets?
>>> There seems to be two ways to do this. One is using one of the 
>>> QScreen
>>> signals:
>>>   http://doc.qt.io/qt-5/qscreen.html
>> Hm, I should have made my question more clear.
>> The typical way I've seen is to connect to the screenChanged signal of
>> the closest ancestral QWindow (window()->windowHandle()).
>> But, I've found that it's not reliable for certain widgets/certain
>> platforms to do e.g:
>>     QTimer::singleShot(0, [this]() {
>>         connect(window()->windowHandle(), &QWindow::screenChanged,
>>                 this, &MyWidget::handleScreenChanged);
>>     });
>> in my constructor, because depending on how the widget is constructed,
>> the parentage up to a top-level window may not have been established
>> yet, even if I do it in a single-shot timer like this.
> I should clarify this: What I mean is that I've seen situations when
> window()->windowHandle() is 0 here, even if the widget is constructed
> with a full parentage up to a top-level widget.


Call QWidget::create() on your top-level constructor, and it will ensure 
it it has a QWindow

Sérgio Martins | sergio.martins at kdab.com | Senior Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - The Qt, C++ and OpenGL Experts

More information about the Interest mailing list