[Interest] High-dpi fixing for Qt 5.5
Elvis Stansvik
elvstone at gmail.com
Fri Mar 2 16:21:23 CET 2018
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.
Elvis
>
> So, what I should probably be doing is something like:
>
> bool MyWidget::eventFilter(QObject *object, QEvent *event)
> {
> if (event->type() == QEvent::ScreenChangeInternal
> || event->type() == QEvent::WindowChangeInternal) {
> if (window() && window()->windowHandle()) {
> // Window or screen changed, and there is an ancestral
> // QWindow I can use, for example to get the QScreen
> // to look at it's DPI et.c.
> }
> }
>
> return ParentClass::eventFilter(object, event);
> }
>
> But then I'm relying on internal events (QEvent::ScreenChangeInternal
> and QEvent::WindowChangeInternal).
>
>>
>> However, another one seems to be using QDesktopWidget signals:
>>
>> http://doc.qt.io/qt-5/qdesktopwidget.html
>>
>> QApplication has static functions to get the current QDesktopWidget, the
>> current QScreen primary screen and all screens. It also has signals to get
>> notified of screen changes.
>
> AFAIK that only gives me the primary screen, and notification about
> when the primary screen changes, not the screen my widget is on or
> notifications when that changes.
>
> Elvis
>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list