+3 votes
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?

in Engine by (15 points)

3 Answers

+4 votes

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.

by (506 points)
0 votes

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)
by (9,712 points)
0 votes

I had to resize my ScrollContainer and V/H BoxContainer

by (678 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 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 webmaster@godotengine.org with your username.