Using external QML for Slicer custom application?

We’re redesigning the GUI on our Slicer custom application and some designers I spoke to have Qt experience and proposed to supply QML scripts. I am not a Qt dev so I’m unclear if this is compatible with the way we use Qt in Slicer, the versions used, etc - it sounds like it could save some boring coding if so.

Anyone know more or even done this themselves? I was also asked how Qt interacts with Python since some of the Qt tools emit C++ code too, but we do pretty much all development in Python.

Based on our prior experience, if the whole application is written in QML, the challenge was the integration with VTK viewers (it is related to sharing of OpenGL context). Note that, this comment is based on experiments done a while back and it may be worth revisiting.

Now, if specific components are written in QML, this shouldn’t be an issue.

1 Like

You can also use Qt Designer - creating complex GUI widgets without coding. See discussion in this thread: Workflow that brings together a few modules as tabs in a unifying parent module.

1 Like

Thanks guys. @lassoan knows our project intimately but more generally, if someone did design and had QML scripts, how would we benefit from that in Python without having to write all the code - is that what Qt Designer does or are they separate ways to do something similar? I’ve not used either but both Qt-familiar designers I spoke to today were telling me how great QML is :slight_smile:

Qt Quick Designer does the same thing as Qt Designer, but the first generates QML (web & mobile app look&feel by default) while the second generates UI files (traditional desktop look&feel by default). Both designers allow specifying properties and making connections between GUI elements (in QML you can even use JavaScript), so some GUI behavior can be defined at that level - probably this is the reason why designers like them (especially QML, which feels very familiar for web designers). There is no difference in how much code you need to write to implement the application logic.

1 Like

Is it pyqt used in Slicer?

I believe it is actually PythonQt (http://pythonqt.sourceforge.net). It is similar to PyQt.

1 Like

PythonQt and pyqt do the same thing (allow Qt to be used from Python), but in Slicer, we chose to use PythonQt, as it comes with a non-restrictive license that allows commercial use for free. Pyqt with non-restrictive license costs $550 per developer.

PythonQt has a number of advantages: it automatically generates code, so the library is much smaller and easier to maintain; applications are not implemented by extending Python but instead native applications embed Python (which allows much cleaner message processing and threading), etc. Unfortunately, its developers do not advertise this library at all, so it is not widely known.

In addition to wheat Andras says, I’ll just also mention that there is also PySide, which is like PyQt but without the restrictive licensing. It did not exist at the time we decided on PythonQt. Overall PythonQt has worked very well for us, but I also note that PySide is now Qt for Python and is an official part of the Qt ecosystem so we’ll keep an eye on that in case there’s a motivation to change in the future.

It would be better to use mainstream libraries, but for me it looked like that similarly to PyQt, PySide takes over the application (Python is the executable) and does not allow an application to embed Python. With embedding Python, we have full control over message processing and threading in our application and Python remains an optional component.

It is hard to tell if it is worth giving up this full control. If current trends continue and Python becomes the standard computing environment for most researchers then we may give in: make Python a required dependency, switch to PySide, and convert all Slicer components to Python packages and build/distribute Slicer via anaconda.

Opening this back up. I am interested in making a touch screen interface with 3D slicer. The widgets are great for desktop with mouse, but leave something to be desired when it comes to touch screen interfaces.

I see that PythonQt supports QtQml and QtQuick submodules, but these do not seem to be included in Slicer. Are there plans to add them, or has anyone done this already on another branch?

We usually implement touch-friendly interfaces using classic widgets with appropriate style sheets.

It would be nice if you could try to build Slicer with Qml and Quick enabled in PythonQt and see how things work. If you find that it works very well then we can consider enabling them by default.

1 Like

@lassoan
I have tried building slicer with QtQuick turned on in pythonqt. However, I am still not seeing any of the qml/qt quick objects in the python interpreter.

I turned them on by enabling PYTHONQT_WRAP_QTALL through passing it into the suberbuild cmake generation.

I see in the cmake gui that it appears to be enabled after configuration.

image

Is there a better way to make sure it is actually being enabled and built with this option?

EDIT:
Im pretty sure it isnt actually enabled correctly in the superbuild. If I do an autocomplete for
PythonQt. I see Qt, QtCore, QtGUI, QtNetwork and QtUiTools

PythonQt is now on GitHub: https://github.com/MeVisLab/pythonqt. I would recommend to post a question in their issue tracker about this.

Ok. I got it to build with QML support, but unfortunately I am not able to get any QML to display. I get a blank white box for everything that I try. Will keep looking into it.

1 Like