MeVisLab Scripting Reference
Python Qt Binding

Introduction

MeVisLab offers the complete Qt Framework API to the Python programmer.

Details

MeVisLab offers the following Qt bindings located in the PythonQt package:

  • Qt (all frameworks in one module, mainly for compatibility with PySide/PyQt4, it is better to just include the individual bindings that are really needed)
  • QtCore
  • QtGui
  • QtNetwork
  • QtSvg
  • QtSql
  • QtOpenGL
  • QtXml

The individual bindings can be dynamically imported using

from PythonQt import QtCore, QtGui, ...

or alternatively importing individual classes:

from PythonQt.QtCore import QObject, ...
from PythonQt.QtGui import QPushButton, QRadioButton, ...

For detailed documentation of the Qt libraries, see http://doc.qt.io/qt-6/reference-overview.html.

Interaction with the MDL

There are two possibilities to use QtGui components:

  • You can generate your own windows/widgets elements using QtGui directly (without using the MDL)
  • You can add Qt widgets to existing MDL layouts dynamically

An example of adding Qt widgets via the initCommand of an MDL control:

yourmodule.script:

Window {
Vertical { initCommand = initVertical }
}

yourmodule.py:

from PythonQt.QtGui import QRadioButton
def radioButtonToggled(state):
print state
def initVertical(control):
button = QRadioButton()
button.text = "Some radio button"
button.connect("toggled(bool)", radioButtonToggled)
control.layout().addWidget(button)

Compatibility to other Qt bindings

While trying to be compatible to other Python/Qt binding like PyQt4 and PySide, there are many subtle differences. One major difference is that in MeVisLab, Qt properties are first class citizens and shadow the getter methods, while in PyQt4 and PySide the getters shadow the properties. Basically it should not be much work to get PyQt4 or PySide example to work in MeVisLab, by replacing the imports with PythonQt imports and by changing getter calls to property reads, e.g., w.height() becomes w.height in MeVisLab.