+5 votes

I want to use the scrollcontainer to contain a texturerect,but i want to hide the scrollbar.
Just hide the scrollbar not disable the scrollbar.
I need to scroll the texture down and up.
How to do this!

in Engine by (19 points)

5 Answers

+18 votes

I'm not sure if this is the right way to do it, but I've achieved this effect in the past by adding a theme to the ScrollContainer, or any GUI node above it in the hierarchy.

Edit the theme, and choose "Add Class Items" from the "Edit Theme" button, choose HScrollBar and/or VScrollBar. Then in the settings for those types, set the various styles to NewStyleBoxEmpty. The scrollbar will no longer be drawn. I've put together a simple example of hiding just the HScrollbar, here.

by (321 points)

thx got it~
u really solved my problem!
thx very much!

I am not sure there is a better way to solve this.
but I'm using the same way as what @pgregory said for a long time.

+3 votes

Other workarounds if you don't want to mess with themes:

  • If you want to still be able to drag the scroll bar, but want it invisible:
    ScrollContainer.get_h_scrollbar().modulate = Color(0, 0, 0, 0)

  • If you want it gone:
    ScrollContainer.get_h_scrollbar().rect_scale.x = 0

by (32 points)
–3 votes

for anyone who might stumble upon this, I want to add that the easiest way I mange to do this is to edit the rect size of the scrollcontainer and making slightly bigger than the screen so the scrollbar would be on the outside, hence not visible.

by (25 points)
+1 vote

Use this code right in the func _read(): (or whatever you want):

extends ScrollContainer

func _ready() -> void:
    disable_scrollbars() #Run the function to disable the scrollbars

func disable_scrollbars():
    var invisible_scrollbar_theme = Theme.new()
    var empty_stylebox = StyleBoxEmpty.new()
    invisible_scrollbar_theme.set_stylebox("scroll", "VScrollBar", empty_stylebox)
    invisible_scrollbar_theme.set_stylebox("scroll", "HScrollBar", empty_stylebox)
    get_v_scrollbar().theme = invisible_scrollbar_theme
    get_h_scrollbar().theme = invisible_scrollbar_theme
by (20 points)
0 votes

There is now an option in Godot 4: https://github.com/godotengine/godot/pull/48008
If anyone wants it in 3.x make sure to let them know.

by (32 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.