Dear all,
I am working on a code to add a ctk widget in the 3D rendering in the upper right corner.
I have currently something working but I was wondering if there is something more elegant that what I have done.
# Get the 3D view widget
threeDWidget = slicer.app.layoutManager().threeDWidget(0)
threeDView = threeDWidget.threeDView()
viewNode = threeDView.mrmlViewNode()
# In the axes widget the order of labels is: +X, -X, +Z, -Z, +Y, -Y
# and in the view node axis labels order is: -X, +X, -Y, +Y, -Z, +Z.
axesLabels = [
viewNode.GetAxisLabel(1), # +X
viewNode.GetAxisLabel(0), # -X
viewNode.GetAxisLabel(5), # +Z
viewNode.GetAxisLabel(4), # -Z
viewNode.GetAxisLabel(3), # +Y
viewNode.GetAxisLabel(2), # -Y
]
# Create the axes widget
self.axesWidget = ctk.ctkAxesWidget()
self.axesWidget.setFixedSize(100, 100)
# Set the labels on the axes widget
self.axesWidget.setAxesLabels(axesLabels)
self.axesWidget.setAutoReset(True)
# Set connections
self.axesWidget.currentAxisChanged.connect(self.lookFromAxis)
layout = qt.QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.axesWidget)
# Add axes widget and make the background transparent
self.overlay = qt.QWidget(threeDView)
self.overlay.setFixedSize(100, 100)
self.overlay.setLayout(layout)
self.overlay.setAttribute(qt.Qt.WA_TranslucentBackground, True)
self.overlay.setStyleSheet("background-color: rgba(0, 0, 0, 128);")
self.overlay.installEventFilter(self)
the event filter play this fucntion
#------------------------------------------------------------------------------
def updateAxesWidgetPosition(self):
"""
Update the position of the axes widget in the 3D view.
"""
layoutManager = slicer.app.layoutManager()
if layoutManager is None:
return
threeDView = layoutManager.threeDWidget(0).threeDView()
# Get size of the 3D view widget
threeDViewSize = threeDView.size
# Compute position for top-right corner
popupWidth = self.overlay.width
x = threeDViewSize.width() - popupWidth
y = 0
self.overlay.move(x, y)
Thank you very much for you help and advice,
Pierre