Jump to content

how to set focus to dialog child?


photo

Recommended Posts

See attached test scene.

 

EditLine is created in main window on init and calls setFocus(). Typing immediately after world load affects editline contents as expected. No problems here.

 

Click button to open new dialog containing another EditLine, also with setFocus() called on init, but focus is still not on this editline. Typing does not affect editline contents until mouse is clicked on editline. Instead, Ok button appears to have focus. Notice how Ok button is colored differently, and pressing spacebar or enter key after opening dialog causes dialog to close.

 

What am I doing wrong? How can I get EditLine widget to be focused on dialog init?

test.cpp

Link to comment

Hi Adam,

the problem is WidgetDialog sets focus to ok button when gets shown. You can disable this in engine(remove "if(child(gui->getFocus())) ok_b->setFocus();" line in WidgetDialog.cpp) or use WidgetWindow instead, or use dirty hack on init:

d.setPermanentFocus();	
e.setFocus();	
int focus_set = 0;	
while(d.isDone() == 0) {
	if(!focus_set && !e.isFocused()) {
	     e.setFocus();
	     focus_set = 1;
	}
        wait;
}
Link to comment
×
×
  • Create New...