Using external QML for Slicer custom application?


(John D) #1

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.

(Jean Christophe Fillion Robin) #2

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.

(Andras Lasso) #3

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.

(John D) #4

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:

(Andras Lasso) #5

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.

(John D) #6

Is it pyqt used in Slicer?

(James Butler) #7

I believe it is actually PythonQt ( It is similar to PyQt.

(Andras Lasso) #8

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.

(Steve Pieper) #9

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.

(Andras Lasso) #10

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.