QML.jl
QML.jl copied to clipboard
wrong image size on Ubuntu with Julia Display
Running "example/plot.jl" gives me this:

I think it may be a linux specific problem (I installed QML using the libraries in #52).
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.
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.
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?
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
Thanks, I'll try that in my use case.
See here: https://twitter.com/josef_heinen/status/812324559517052928
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:

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?
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!
Are you using Ubuntu, Hombrew or the official qt.io Qt5 ?
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
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.
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.
In the meantime, you can use native GR/Qt graphics with QML, as shown in this GR example.

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