QML.jl icon indicating copy to clipboard operation
QML.jl copied to clipboard

wrong image size on Ubuntu with Julia Display

Open piever opened this issue 7 years ago • 14 comments
trafficstars

Running "example/plot.jl" gives me this:

qml

I think it may be a linux specific problem (I installed QML using the libraries in #52).

piever avatar Jan 23 '18 15:01 piever

Update: it is actually not strictly a QML issue. The display size issue only happen with the GR backend. Gtk is also affected, for example:

using Plots, Gtk
gr()
plot(rand(100))
tmp = tempname() * ".png"
savefig(tmp)

img = GtkImage(tmp)

win = GtkWindow("test")
push!(win, img)
showall(win)

would show an image much bigger than the original png. It wouldn't happen with a different backend (have tried plotlyjs to confirm). I suspect it started with #1318, I'm pinging @jheinen as he probably knows what's going on.

piever avatar Jan 26 '18 15:01 piever

Hi,

Sorry for my late reply, but this is probably the device pixel ratio. The gr.jl example takes this into account. The trick is to pass the QML item to the callback, and then use the effectiveDevicePixelRatio function to get the ratio between image pixels and screen pixels.

barche avatar Jan 29 '18 14:01 barche

Hi, thanks for looking into this. I actually do not believe this has to do with effectiveDevicePixelRatio as it used to work fine on my Mac retina screen (which has an effectiveDevicePixelRatio of 2). I believe the issue is specific to GR due to the way they save PNG, which changed recently (see for example this comment ). Can you reproduce the problem if you check out the latest Plots and GR and try the example on your setup?

piever avatar Jan 29 '18 14:01 piever

There s no need to use PNGs in QML/GR environments. You can directly draw into the widget provided by Qt, which is much faster.

GR example: https://github.com/jheinen/GR.jl/blob/master/examples/qml_ex.jl Plots + GR example: https://github.com/jheinen/GR.jl/blob/master/examples/qml_plots_ex.jl

QML file: https://github.com/jheinen/GR.jl/blob/master/examples/qml_ex.qml

jheinen avatar Jan 29 '18 14:01 jheinen

Thanks, I'll try that in my use case.

piever avatar Jan 29 '18 14:01 piever

See here: https://twitter.com/josef_heinen/status/812324559517052928

jheinen avatar Jan 29 '18 15:01 jheinen

Probably not the right place to report this, but I'm having issues running your example on Ubuntu:

julia> Pkg.status("GR")
 - GR                            0.25.0

julia> ENV["GRDIR"]=""
""

julia> Pkg.build("GR")

julia> GR.version()
"0.28.0"

julia> include(joinpath(Pkg.dir("GR", "examples"), "qml_plots_ex.jl"))
GKS: Qt5 support not compiled in

I imagine is a similar issue to this comment but for the Ubuntu precompiled binaries.

I get the QML window, with the slider, which detects my mouse position but no plot appears:

gr_qml

piever avatar Jan 29 '18 20:01 piever

We have to fix this in our CI environment or provide a method which would allow the user to build such extensions, e.g. the Qt5 plugin. You are using Ubuntu, right?

jheinen avatar Jan 30 '18 09:01 jheinen

Yes, I have an ubuntu machine (which has this issue) and a mac (on which I can run your QML+GR example). Thanks for looking into this!

piever avatar Jan 30 '18 15:01 piever

Are you using Ubuntu, Hombrew or the official qt.io Qt5 ?

jheinen avatar Jan 30 '18 16:01 jheinen

I installed QML libraries on my ubuntu machine using this command:

sudo apt-get -y install cmake cmake-data qtdeclarative5-dev qml-module-qtquick-controls qml-module-qtquick-dialogs qml-module-qt-labs-folderlistmodel qml-module-qt-labs-settings qmlscene qt5-default

piever avatar Jan 30 '18 16:01 piever

Update: I've noticed that, at least on Gtk, the GR plot saved as svg displays correctly as a GtkImage. I was wondering whether it's possible to change the JuliaDisplay type in QML to use svg format rather than png to display the plot. In Plots.jl language that would be mimeformat "image/svg+xml" rather than "image/png". If you believe that for some backends png is better (which may well be) there could be an attribute of JuliaDisplay that allows the user to choose between svg and png.

piever avatar Feb 14 '18 11:02 piever

Well, this was easier than I thought, so now it uses SVG if available and falls back to PNG otherwise. Probably some config options would be good to have, as well as a translation of the Julia MIME type to Qt so all Qt image formats would be supported automatically.

The plots example in master automatically picks this up.

barche avatar Feb 18 '18 22:02 barche

In the meantime, you can use native GR/Qt graphics with QML, as shown in this GR example. qml gr_on_ubuntu

So, there is no need for PNGs or SVGs to display graphics in QML. The above method is much faster!

jheinen avatar Jun 19 '18 10:06 jheinen