+1 vote

I want to have the vertical scrollbar of a scrollcontainer always visible. The default behavior is that the scrollbars only show up when they are required. My problem is that when the scrollbar appears because of the child gets larger than the scrollcontainer, it also changes the available size of the container so the alignment gets shifted left.

I tried to understand the mechanism that shows and hides the scrollbars but even by printing the entire property list values of the scrollbar I am not able to see any difference between when it is hidden and when it is shown. The visible property of the scrollbars is always true even when the scrollbars are not drawn.

in Engine by (120 points)

2 Answers

+2 votes
Best answer

The vertical scrollbar gets hidden when the height of the contents are small, and it's a hardcoded behavior: https://github.com/godotengine/godot/blob/1a532d53ccfd11cae7efdda1d406fd26da5cdb1e/scene/gui/scroll_container.cpp#L426

The only configuration is to hide it always, by setting scroll_vertical_enabled to false.

Visible scrollbars effectively reduce the size of the layout area, which is also not configurable. Here is the code where it plays a role: https://github.com/godotengine/godot/blob/1a532d53ccfd11cae7efdda1d406fd26da5cdb1e/scene/gui/scroll_container.cpp#L286

The options I see are:
- Hide scrollbars and make your own outside of the container
- Change the engine code to adapt it to your needs
- Add an option to the engine's code to keep scrollbar visible and make a PR
- Ask for the feature in the Godot Proposals repo

by (29,046 points)
selected by

Thanks for the thorough answer. At least I know that it is a limitation and I can stop hitting my head on the wall. For now I will make the scrollcontainer at least one pixel smaller than his child to make the scrollbar appear all the time. Not a perfect solution but fast amd will allow me to move forward. I have no idea how to do cpp but I will consider requesting the feature.

+1 vote

By using a custom theme, you can edit the "V Scroll Bar" Class and set an StyleBoxEmpty to every styles using the inspector.

by (24 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.