I am developing an extension to display the results of some neuro image processing which involves reading a CSV file into a table. I need the table to be a popup and the following code snippet from the slicer website does this:
What I want to do next is to detect a table selection change and return the contents of column 1 of the newly selected row. I can then load a particular image based on the cell contents.
If I create a table node which is part of the main UI I can read a CSV file and populate the table easiliy enough and then run code when the table selection is changed using the line below. This does not work for the tableModuleWidget as created above. Is there a way to do this please?
createnewwidgetrepresentation should not be used by modules, as module widgets are usually implemented so that they assume that there is only a single instance of them.
Instead, you can use a slicer.qMRMLTableView() or maybe a slicer.qMRMLTableWidget(). However, in general, I would advise against popups, as it disrupts the user’s workflow, and instead display the table in your module widget, in the view layout (either choose an existing layout that already has a table view in it, or define a new custom layout), or at least put the widget in a dockable window and dock it somewhere in the application window (for example, see NodeInfo module in DebuggingTools extension).
For developers’ convenience, a simple selectionChanged() signal has been added to the table qMRMLTableView that you can connect to callback functions. Also, qMRMLTableView is a QTableView, so you can connect callbacks to selection model changes as you would do on any regular QTableView object.
Jumping to segment based when a table table cell is selected is implemented in QuantitativeReporting extension, you can use that as an example.