sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

Programmatic resizing of qt plot window works poorly on tiling window managers #63

Closed c42f closed 5 years ago

c42f commented 5 years ago

Tiling window managers will not respect calls to QWidget::resize() in general, which causes odd behavior in GKS QtTerm. In particular, the widget should not assume that the resizeEvent() generated by a call to resize() will have the desired width and height.

A simple fix is complicated by the Qt bug https://bugreports.qt.io/browse/QTBUG-57608 which means qt itself will not realize the window is not the desired size, causing such weird visual artifacts as 2018-10-11-101331_958x528_scrot where an unrelated plot (generated by GR.jl) appears partially on top of an old one. This occurs when plotting into the same window multiple times.

I can work around the problem for myself by commenting out the lines in GR.jl which result in calls to gr_setwsviewport, for example commenting out: https://github.com/jheinen/GR.jl/blob/e972de2d6013454422c1461eab1b5de12c6d8995/src/jlgr.jl#L109

One option for a workaround in GR would be to supply an option which prevents gr_setwsviewport from programmatically resizing the window (though it could recentre the plot within the existing window).

FlorianRhiem commented 5 years ago

After the failed resize, Qt is insistent on the wrong "new" window size, so there is no option to detect the actual size from within Qt or to even clear the area now considered "outside" the window. This should be fixed in Qt 5.10 according to the bug report from your link.

I have added an environment variable GKS_GKSQT_PREVENT_RESIZE that can be set to a non-empty value to prevent the regular resizing of gksqt based on the wsviewport. The window will then stay the same size but it's background will be filled white and the actual content will be centered.

c42f commented 5 years ago

Just what I was looking for, thanks! However it doesn't quite work yet - the plot size is halved each time I replot into the same window.

FlorianRhiem commented 5 years ago

Thank you for the feedback, I was able to reproduce this issue. It is caused by the physical size (in meters) and logical size (in pixels) running out of sync when resizing is prevented. This will be fixed by updating the physical size anyway, by using the Qt-reported physical and logical window size to determine the screen resolution (in pixels/m) and multiplying that by the user-desired logical size.

FlorianRhiem commented 5 years ago

Did you encounter this problem again since the fix in v0.35.0?

c42f commented 5 years ago

The latest version is a great improvement: the plot no longer halves each time and is correctly centered within the fixed-size window.

Having said that, the plot size doesn't scale to fill the (fixed) window size which is inconsistent with windows which are resized manually. I'm not sure whether this is a bug or not, it depends on your definition of how plots should be scaled to fit real world screens.

FlorianRhiem commented 5 years ago

Which Qt version are you using? This might still be due to the issue in Qt (before 5.10) that the correct dimensions aren't reported to the program, as we use the width and height reported during resize events.

c42f commented 5 years ago

It looks like I was using 5.9 so I tried upgrading to 5.11.1 and setting that as the default qt. I've verified that gksqt is using libQt5Core.so.5.11.1 now.

Digging further into this, the issue is a combination of having set GKS_GKSQT_PREVENT_RESIZE=1 with the latest Qt-5.11.1. If I unset that variable the problem goes away.

FlorianRhiem commented 5 years ago

Great, so the environment variable works as a workaround for the broken resizing with overlapping plots on old Qt versions and everything works correctly on newer Qt versions. Thanks for testing this!

c42f commented 5 years ago

Thanks for the fix!