> On 24 Mar 2015, at 14:26, Till Oliver Knoll <[email protected]> > wrote: > > > Am 19.03.2015 um 14:17 schrieb Sorvig Morten <[email protected]>: > >> Hi, >> >> ... >> >> In case there issues that I’ve missed I would be interested in hearing about >> it. I can’t promise that everything will be fixed, but it will be at least >> put on the radar. > > Hi Morten, > > Not a bug by itself and hence a bit off-topic, but is there a way to detect > "screen resolution changes" in some way? The use case is of course when an > application window is moved from a Retina (HiDPI) screen to a non-Retina > screen (or vice versa) (in a multi-monitor setup). > > My knowledge of available "HiDPI" APIs is currently based on your (excellent) > blog post, which does not seem to mention that use case: > > > http://blog.qt.io/blog/2013/04/25/retina-display-support-for-mac-os-ios-and-x11/ > > I could imagine that getting informed e.g. by the QDesktopWidget (or some > other related "screen/resolution" class) whenever the application is > "switched" (dragged) to another screen, and then querying the resolution of > the new screen, could be a solution. However I currently do not see any > corresponding signal in QDesktopWidget's API, nor anywhere else…
[I see there has been other replies which covers this, so there’s probably some duplicate information here.] The current approach is that application windows will be repainted at screen change time; The window's devicePixelRatio() accessor will then return the correct value for the new screen and the app will draw at the correct pixel density. > > In the end I am not even sure whether I need to get informed about this > event, since most drawing - and also the switch between Retina/non-Retina > worlds - is handled for me already by Qt/underlying Core Graphics APIs. Even > the Apple Developer docs mention that "Listening for > NSWindowDidChangeBackingPropertiesNotification is something only a few apps > [...] will need to do." > > However my app probably /is/ one of those that "specialize in video or > graphics work". I draw on a QGraphicsView(-scene) and have > QGraphicsPixmapItems with a QPixmap behind them. I imagine that I have to be > able to dynamically switch between the normal and the "@2x" version of those > pixmaps, and have the QGraphicsView paint itself whenever such a "resolution > change" is detected. Or so I imagine… Pixmaps caches are indeed a special case: you need to factor in the target devicePixelRatio when creating the caches: qreal dpr = window->devicePixelRatio(); // or painter->device()->devicePixelRatio() QPixmap cache(size * dpr); cache.setDevicePixelRatio(dpr); // iff you want scale any QPainters opened on the pixmap. (this is a recurring pattern and may deserve its own API at some point) > > So I am basically looking for a "cross-platform" way to get notified in > analogy to the Cocoa notification > > NSWindowDidChangeBackingPropertiesNotification > > See chapter "Handle Dynamic Changes in Window Resolution Only When You Must" > > https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//apple_ref/doc/uid/TP40012302-CH10-SW1 > Looks like the desktop platforms (XCB, OS X and Windows) emit QWindow::screenChanged now. I think the best place to handle the pixel density change is still the repaint, that way you create new graphics at the correct time. Morten _______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
