# How to add a border to 3d widget

**URL:** <https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221>\
**Category:** Development\
**Tags:** python\
**Created:** [August 17, 2021, 7:01am UTC](https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221 "2021-08-17T07:01:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wycstar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/wycstar/32/11800_2.png) [@wycstar](https://discourse.slicer.org/u/wycstar)\
**Post date:** [August 17, 2021, 7:01am UTC](https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221/1 "2021-08-17T07:01:41Z")

</div>

I want to add a border to 3d widget, but run the code below, nothing happened

```auto
slicer.app.layoutManager().threeDWidget(0).threeDView().setStyleSheet("border-bottom: 2px solid rgb(255, 0, 0)")

```

where am i wrong

---

<div class="post-metadata">

**Author:** ![wycstar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/wycstar/32/11800_2.png) [@wycstar](https://discourse.slicer.org/u/wycstar)\
**Post date:** [August 18, 2021, 3:16am UTC](https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221/2 "2021-08-18T03:16:35Z")

</div>

@lassoan save me plz 🤣

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 18, 2021, 2:58pm UTC](https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221/3 "2021-08-18T14:58:04Z")

</div>

The VTK render window is painted by VTK, so style sheet will have no effect. You can draw the frame by using VTK by adding a 2D actor:

```python
view = slicer.app.layoutManager().threeDWidget(0).threeDView()
color = [0.0, 1.0, 1.0]
lineThickness = 10.0

viewRenderer = view.renderWindow().GetRenderers().GetItemAsObject(0)

borderPoints = vtk.vtkPoints()
borderPoints.InsertNextPoint( 1e-4, 1e-4, 0)
borderPoints.InsertNextPoint(0.9999, 1e-4, 0)
borderPoints.InsertNextPoint(0.9999, 0.9999, 0)
borderPoints.InsertNextPoint( 1e-4, 0.9999, 0)

borderCells = vtk.vtkCellArray()
borderCells.InsertNextCell(5)
for i in range(5):
    borderCells.InsertCellPoint(i%5)

borderPolyData = vtk.vtkPolyData()
borderPolyData.SetPoints(borderPoints)
borderPolyData.SetLines(borderCells)

borderCoordinate = vtk.vtkCoordinate()
borderCoordinate.SetCoordinateSystemToNormalizedViewport()
borderCoordinate.SetViewport(viewRenderer)

borderPolyDataMapper = vtk.vtkPolyDataMapper2D()
borderPolyDataMapper.SetInputData(borderPolyData)
borderPolyDataMapper.SetTransformCoordinate(borderCoordinate)
borderPolyDataMapper.SetTransformCoordinateUseDouble(True)

highlightedBorderActor = vtk.vtkActor2D()
highlightedBorderActor.SetMapper(borderPolyDataMapper)
highlightedBorderActor.GetProperty().SetColor(color[0], color[1], color[2])
highlightedBorderActor.GetProperty().SetDisplayLocationToForeground()
highlightedBorderActor.GetProperty().SetLineWidth(lineThickness)
viewRenderer.AddActor2D(highlightedBorderActor)
view.renderWindow().Render()

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/9/292416681d0b0eeb772023fecb3cf32d7a8ad620.png)

---

<div class="post-metadata">

**Author:** ![wycstar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/wycstar/32/11800_2.png) [@wycstar](https://discourse.slicer.org/u/wycstar)\
**Post date:** [August 19, 2021, 2:41am UTC](https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221/4 "2021-08-19T02:41:00Z")

</div>

thanks @lassoan it works!

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [January 4, 2022, 11:33pm UTC](https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221/5 "2022-01-04T23:33:14Z")

</div>

What about to disable it?  
I´ve tried to repeat the process with lineThickness=0 but it doesn´t work for me. Is there any way to get this vtkActor2D to remove it?

Thanks on advance!

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [January 5, 2022, 12:57am UTC](https://discourse.slicer.org/t/how-to-add-a-border-to-3d-widget/19221/6 "2022-01-05T00:57:58Z")

</div>

I answer to myself FYI:

```auto
for actor2D in viewRenderer.GetActors2D():
        viewRenderer.RemoveActor2D(actor2D)

```
