# vtkScalarBarWidget stuck on vertical orientation

**URL:** <https://discourse.vtk.org/t/vtkscalarbarwidget-stuck-on-vertical-orientation/10217>\
**Category:** Development\
**Created:** [December 15, 2022, 8:56pm UTC](https://discourse.vtk.org/t/vtkscalarbarwidget-stuck-on-vertical-orientation/10217 "2022-12-15T20:56:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)\
**Post date:** [December 15, 2022, 8:56pm UTC](https://discourse.vtk.org/t/vtkscalarbarwidget-stuck-on-vertical-orientation/10217/1 "2022-12-15T20:56:41Z")

</div>

I’m using Vtk 9.1 on Linux.

I’ve been trying to get a vtkScalarBarWidget to orient horizontally. I’ve found that the vtkScalarBar will, but I can’t figure out how to do this with the widget.

From the online example:

[https://kitware.github.io/vtk-examples/site/Cxx/Widgets/ScalarBarWidget/](https://kitware.github.io/vtk-examples/site/Cxx/Widgets/ScalarBarWidget/)

The vtkScalarBar is set to horizontal with  
scalarBar-\>SetOrientationToHorizontal();  
but the widget is always vertical.

I can move the widget with the mouse and when it is near the bottom of the viewport, it changes to horizontal.

How can I set this in my program to be horizontal by default?

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [December 20, 2022, 1:08pm UTC](https://discourse.vtk.org/t/vtkscalarbarwidget-stuck-on-vertical-orientation/10217/2 "2022-12-20T13:08:50Z")

</div>

Hello,

`SetOrientationToHorizontal()` is a `vtkScalarBarActor` method. It is an actor, that is, the thing that appears in the scene inside the widget, which is a `vtkScalarBarWidget`. So, you need to act upon the widget, not the actor. `vtkScalarBarWidget` has a `GetScalarBarRepresentation()` method which returns a pointer to a `vtkScalarBarRepresentation` object. Maybe you want to try exploring its API to achieve the effect you want: [https://vtk.org/doc/nightly/html/classvtkScalarBarRepresentation.html](https://vtk.org/doc/nightly/html/classvtkScalarBarRepresentation.html). Perhaps its `SetOrientation(int)` or `SetPostion()` methods will do.

take care,

Paulo

---

<div class="post-metadata">

**Author:** ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)\
**Post date:** [December 28, 2022, 12:45am UTC](https://discourse.vtk.org/t/vtkscalarbarwidget-stuck-on-vertical-orientation/10217/3 "2022-12-28T00:45:33Z")

</div>

Hi Paulo,

I was able to use the following to set the orientation to horizontal:

auto rep = scalarBarWidget-\>GetScalarBarRepresentation();  
rep-\>SetOrientation(0);

I was able to use the following to set the position:

auto bord = scalarBarWidget-\>GetBorderRepresentation();  
bord-\>SetPosition(0.1, 0.02);  
bord-\>SetPosition2(0.8, 0.05);

What I haven’t been able to figure out is how to change the font properties.

BK

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [December 29, 2022, 6:44pm UTC](https://discourse.vtk.org/t/vtkscalarbarwidget-stuck-on-vertical-orientation/10217/4 "2022-12-29T18:44:03Z")

</div>

> [@BlueKnight7](#):
>
> What I haven’t been able to figure out is how to change the font properties

Please, post another question for that. 🙂
