How to add button on 2d or 3d window?

Good question - this code seems to work. You’d need to add some extra code if you want to have it show up in the lower right corner and track window resizes and things.

>>> sliceButton = qt.QPushButton("Slice")
>>> sliceButton.setParent(slicer.app.layoutManager().sliceWidget("Red"))
>>> sliceButton.geometry = qt.QRect(0,0,200,200)
>>> sliceButton.show()
>>> 

1 Like