Hi,
I can’t actually find a comprehensive example how Slicer uses PythonQt to wrap C++ classes to python.
I’ve seen examples on PythonQt github but can’t apply it to my class.
For example I can do:
import PythonQt
dir(PythonQt)
the output would be:
['BoolResult', 'CTKCore', 'CTKScriptingPythonWidgets', 'CTKVisualizationVTKCore',
'CTKVisualizationVTKWidgets', 'CTKWidgets', 'Debug', 'Qt', 'QtCore', 'QtGui', 'QtNetwork', 'QtUiTools',
'__doc__', '__loader__', '__name__', '__package__', '__spec__', 'private', 'qMRMLWidgets',
'qSlicerAnnotationsModuleWidgets', 'qSlicerBaseQTApp', 'qSlicerBaseQTCLI', 'qSlicerBaseQTCore',
'qSlicerBaseQTGUI', 'qSlicerMarkupsModuleWidgets', 'qSlicerMarkupsSubjectHierarchyPlugins',
'qSlicerModelsModuleWidgets', 'qSlicerModelsSubjectHierarchyPlugins', 'qSlicerPlotsModuleWidgets',
'qSlicerPlotsSubjectHierarchyPlugins', 'qSlicerSegmentationsEditorEffects',
'qSlicerSegmentationsModuleWidgets', 'qSlicerSegmentationsSubjectHierarchyPlugins',
'qSlicerSequencesModuleWidgets', 'qSlicerSubjectHierarchyModuleWidgets',
'qSlicerTablesModuleWidgets', 'qSlicerTablesSubjectHierarchyPlugins',
'qSlicerTerminologiesModuleWidgets', 'qSlicerTextsModuleWidgets',
'qSlicerTextsSubjectHierarchyPlugins', 'qSlicerTransformsModuleWidgets',
'qSlicerTransformsSubjectHierarchyPlugins', 'qSlicerUnitsModuleWidgets',
'qSlicerVolumeRenderingModuleWidgets', 'qSlicerVolumeRenderingSubjectHierarchyPlugins',
'qSlicerVolumesModuleWidgets', 'qSlicerVolumesSubjectHierarchyPlugins']
then I look to GUI elements:
dir(PythonQt.qSlicerBaseQTGUI)
and among many output classes I can see qSlicerDirectoryListView
for example. Assuming that this class was written in C++ and binded to python I search for qSlicerDirectoryListView.h
and qSlicerDirectoryListView.cxx
. I have found them in Base/QTGUI/
folder. To my surprise these files doesn’t contain any PythonQt
mentionning…
From my point of view to bind C++ class to python I need to add somwhere #include <PythonQt.h>
and PythonQt::self()->registerClass(&qMyClass::staticMetaObject);
. And to check if it works I should run my application and in python interpreter do something like:
import PythonQt
dir(PythonQt)
and among the output I should be able to find qMyClass
. Am I right? Though suspiciously simple