Add HiDPI support for the Qt toolkit#591
Conversation
|
This looks generally fine in terms of implementation. I haven't taken it for a spin yet, so there may be some glitches out there still. There are some edge-cases that I can see around what happens if the resolution changes while the window is live (either by the user changing the resolution, or moving between screens), but as-is should be no worse than what we have now. I think it can be supported in Qt if we wanted to go there, but worst case is that you get low-resolution images after moving from low-res to high-res; or you render at high-res when working with low-res. This PR should include some tests: testing the Kiva GCs should be straightforward, but testing that the resolution is set correctly in CI is probably going to need a mock/patch of the appropriate Qt methods - I have no idea what headless boxes are going to report as screen resolution. |
|
Just had a thought where there may be additional breakage: in save methods we probably need to adjust the dpi appropriately. Pillow will take the raw data just fine, but won't pass the scale information through to saved files. |
|
I've added some modifications to the kiva drawing tests which exercise the pixel scaling code. |
|
Shakes fist at OpenGL backend 😠 |
|
#593 added to track saved image DPI concerns. |
|
Playing around with this a little, it seems to be working for the QPainter backend, but I think #390 might be impacting the drawing in the Agg backend - a little hard to tell as the number of pixels a line requires depends on the fractional position of the line - or alternatively it may be that we are snapping lines to coordinates somewhere (I have a vague recollection of such code). |
|
#390 is definitely a factor for the AGG backends. They're definitely implemented incorrectly, but I can only imagine how to fix |
|
Thanks for the testing and feedback. |
HiDPI rendering for Qt 5+. The change is mostly transparent to user code, because kiva drawing is already based on vectors. However, users can opt out by passing `high_resolution=False` to `ComponentEditor`.
HiDPI rendering for Qt 5+. The change is mostly transparent to user code, because kiva drawing is already based on vectors. However, users can opt out by passing `high_resolution=False` to `ComponentEditor`.
This is the Qt half of #412 and #517. I haven't looked into how Wx does HiDPI display yet, but figuring out how to do it for Qt5 first will likely make adding Wx "easy".
Known broken:
Component.use_backbuffercreates a low resolution buffer.GraphicsContext.clip_to_rectuses absolute coordinates, so supporting HiDPI by changing the scale of a GC will break lots of code [but not all] which usesclip_to_rectGraphicsContext.clip_to_rectis not uniformly implemented with respect to the affine transformation across all kiva backends! (Celiagg's clip_to_rect() should respect the transform matrix #592)Covered by Allow scaling in agg's draw_marker_at_points #594GraphicsContext.draw_marker_at_pointsin thekiva.aggbackend will draw nothing if there's anything more than a translation applied to the transformation matrix.