QT designer python code generation, and nodule auto-naming

I have been messing around with creating my own extensions, and was wondering if it was possible at all for code to be generated from the Qt Designer in a python environment.

I see this previous post and that the designer without the generator reduces module size by a significant amount.

My use case is that I have 2 widgets for placing markups included in my extension, and would like for the nodes for each of the individual widgets to be named either ‘nodule’ or ‘background’ so that I can read these values into other code I have written. The only way I can think to do that is by getting access to the node

As of right now, I have added these widgets to the UI, connected their signals to the MRMLscene, but this leaves me with needing to create, and then rename the respective nodes for nodule/background points of interest.

Thank you for any help or suggestions!

just for reference,
image

BG and nod were test markups I manually created/named after updating the UI to make sure they were linked properly to the MRMLscene update.

For the node naming, the qMRMLNodeComboBox has the attribute ‘baseName’ that controls the default name that the node is created with.

2 Likes

Thank you, I will take a look at it when I’m back in office tomorrow. Being able to nodes that will help greatly from a user standpoint.

I did end up finding a method to generate a python script file from the QT .ui file through some youtube tutorials, and I can post the link/steps to that here. The end result isn’t as pretty as the Extension Wizard example that you start off with, but its workable.

Python code generation from .ui file is unnecessary. I don’t know what problems PySide is trying to solve with this clunky code generation stuff, but for all the use cases that I’ve encountered so far, code generation is simply not needed.

Slicer uses PythonQt for Python wrapping, which has many advantages compared to PySide (the Python wrapping that the Qt Company provides), but there are slight differences. PythonQt is not widely known, so most examples that you find on the web are for PySide and not directly applicable to PythonQt.

I am currently looking at the basename attribute for qMRMLNodeComboBox, but have no option to edit it. Are there any special options that I need to include so that it is editable?

Right now if I type in any string for the baseName and hit enter, it just disappears/doesnt apply.

That’s fine, what you see is just a small Qt designer bug that if you edit properties of a widget that is currently not visible (for example, it is in a collapsed widget) then the focus is moved away from the property editor on any modification.

You can either open the collapsible button or groupbox or tab widget while you are editing widgets in it; or copy-paste text into the property editor instead of typing.

1 Like

You can either open the collapsible button or groupbox or tab widget while you are editing widgets in it; or copy-paste text into the property editor instead of typing.

Thank you,

I just got it to work. I just needed to link the scene to a combo button, and then I found the ‘drop down button view’ QT setting to allow me to edit the basename. I additionally had to add ‘vtkMRMLMarkupsFiducialNode’ to the combobox nodetypes, so the point list is created correctly.

Unfortunately, the node selection incorporated in the markups widgets dont have editable baseNames, but I am able to use two combo boxes to create nodes with the foreground/background seed names now, and then the user is able to select those in the markup placement widget.

This is my first time doing UI/QT development so it’s taken me a bit to understand what’s going on.

Thank you!

1 Like

Indeed, not everything is exposed as property that can be edited in Qt Designer, so for some things you need to add a line in the setup method of the module widget - for example self.ui.someMarkupsWidget.setNodeBaseName('something')