How do i use set_focus_child to set focus to a text entry in gtkmm?

StackOverflow https://stackoverflow.com/questions/18591304

  •  27-06-2022
  •  | 
  •  

Вопрос

I have a dialog in which i ask the user to enter username and password. I match them with database. If the user field is empty, i show a message box telling the user that user id is blank. I want the focus to set to user id field. How do i do that in gtkmm? Is it possible to clear the existing contents of the user id?

l_user_id=m_user_id->get_text();
l_password=m_password->get_text();

if(l_user_id=="")
  throw_dialog("Empty Field","Please enter a user name");
  // i want to clear the user id field
  // i want to set focus to user id field
Это было полезно?

Решение

Use Gtk::Widget::grab_focus() and Gtk::Entry::set_text.

l_user_id.set_text("");
l_user_id.grab_focus();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top