Buttons in VBoxContainer (Containers) not resizable

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tadpolily
extends VBoxContainer
var button1
var button2
func _ready():

   button1 = Button.new()
   add_child(button1)
   button2 = Button.new()
   button2.set_size(Vector2(500,500))
   add_child(button2)

I can’t seem to resize the buttons that I add to my VBoxcontainer either through code
or through adding and resizing them manually. They all the same width. Is this by design?

:bust_in_silhouette: Reply From: literalcitrus

VBoxContainer and HBoxContainer by design both try and reduce the size taken up by children Control nodes as much as possible. Because of this, to ensure that a child Control node doesn’t collapse itself you need to set the rect_min_size property instead of the rect_size property.

One caveat is that the width of a control in a VBoxContainer will always be fixed to the width of the VBoxContainer, and the same with height and HBoxContainers. There are ways around this though, such as having a Control node as the direct child of the WhateverBoxContainer, and then a Button as a child of the Control with a smaller width or height.

:bust_in_silhouette: Reply From: volzhs

under Godot 2.1.x

extends VBoxContainer
var button1
var button2
func _ready():
	button1 = Button.new()
	button1.set_h_size_flags(0)
	add_child(button1)
	button2 = Button.new()
	button2.set_h_size_flags(0)
	button2.set_custom_minimum_size(Vector2(500,500))
	add_child(button2)

for Godot 3.0

extends VBoxContainer
var button1
var button2
func _ready():
	button1 = Button.new()
	button1.size_flags_horizontal = 0
	add_child(button1)
	button2 = Button.new()
	button2.size_flags_horizontal = 0
	button2.rect_min_size = Vector2(500,500)
	add_child(button2)
:bust_in_silhouette: Reply From: jarlowrey

I had to resize my ScrollContainer and V/H BoxContainer