vtkScalarBarWidget stuck on vertical orientation

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/

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?

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. Perhaps its SetOrientation(int) or SetPostion() methods will do.

take care,

Paulo

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

Please, post another question for that. :slightly_smiling_face: