This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi.

I've created a modal popup with nested LineEdits, the problem is that the popup closes when I try to select one of the LineEdits with a mouse. TAB-select works fine though. i've tried messing with set_focus_mode and set_stop_mouse but nothing seems to work. Here's a example code.

tool
extends Button

onready var m_popup = Popup.new()
onready var m_x = LineEdit.new()
onready var m_y = LineEdit.new()

func _ready():
    connect("pressed", self, "clicked")

    m_x.set_text("0")
    m_y.set_text("0")

    var hBox = HBoxContainer.new()

    hBox.add_child(m_x)
    hBox.add_child(m_y)

    m_popup.add_child(hBox)
    add_child(m_popup)

func clicked():
   var pos = get_global_mouse_pos()
   pos.x -= 125
   pos.y += 10
   m_popup.set_global_pos(pos)
   m_popup.popup()
in Engine by (23 points)

1 Answer

0 votes
Best answer

That is because a popup is supposed to close when you click somewhere outside of its boundaries and I am going to guess that the LineEdits are not within its margins due to the Container. There are a couple of solutions for this:
You could simply use a normal "Control" and use .show() and .hide() for manipulating its visibility. You can also use these methods on a popup by the way instead of .popup() which will show the Popup without disappearing automatically.
And finally, you can set the popup to "Exclusive" with the method set_exclusive(true) in order to make it hide other popups on the screen and to stay visible.

I hope any of these solutions help you! :D

by (305 points)
selected by

Manually resizing the popup boundaries/size solved this problem. It's interesting, though, that the popup object isn't inherited from a container object. Thanks for pointing me to the right direction!

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.