-
Hi, a LineEdit component on a subcomponent should receive the focus as soon as the window is shown. However, I can't reference the subcomponent, since it is shown conditionally. Is there a way to solve or work around this issue? Slint code (SlintPad)import { Button, LineEdit } from "std-widgets.slint";
export component SubPage1 inherits VerticalLayout {
padding: 8px;
forward-focus: input;
input := LineEdit {
placeholder-text: "Enter text here";
}
}
export component SubPage2 inherits VerticalLayout {
padding: 8px;
button := Button {
text: "Click me";
}
}
export component Main inherits Window {
private property <int> page-index: 0;
preferred-width: 200px;
preferred-height: 50px;
// forward-focus: sub-page1; // does not work
if (page-index == 0): sub-page1 := SubPage1 {}
if (page-index != 0): sub-page2 := SubPage2 {}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
One thing that you could do is set the focus when Careful, if you try this in SlintPad it's going to steal the focus - it can be annoying when editing :-) |
Beta Was this translation helpful? Give feedback.
-
Yes, that works for me. Thank you. |
Beta Was this translation helpful? Give feedback.
One thing that you could do is set the focus when
SubPage1
is created for the very first time, like this: In theinit
callback, callself.focus()
.Careful, if you try this in SlintPad it's going to steal the focus - it can be annoying when editing :-)