[Interest] How to be notified when widget is moved to another screen?

Elvis Stansvik elvstone at gmail.com
Fri Oct 21 09:47:13 CEST 2016


2016-10-21 9:22 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
> Using
>
>     QApplication::desktop()->screenNumber(widget);
>
> it's possible to get the screen number of the screen where the widget
> is mostly visible.
>
> But how can I be notified when this changes for a particular widget?
>
> Must I monitor the widget's moveEvent/resizeEvent/... myself, and
> check if the screen number changed since last time? What about changes
> to the screen configuration (switching monitors) which causes to
> widget to appear on another screen?
>
> The reason I want to be notified is that I'm using another API, VTK,
> which has a quite primitive SetDPI for controlling the DPI used during
> font rendering, and since I was using Qt anyway, I was thinking of
> using Qt for DPI detection (since VTK doesn't have any cross platform
> detection) and also for the detection of when the widget changes
> screen, to know which screen to query for its DPI.

As a rough approximation, I tried connecting to QWindow::screenChanged
of the window() for the widget, but it was never emitted when I moved
the window between monitors.

Elvis

>
> Thanks in advance,
> Elvis



More information about the Interest mailing list