简体   繁体   中英

Adding Gtk::Entry to Gtk::Dialog

I am adding a Gtk::Entry to Gtk::Dialog .

Gtk::Dialog *dialog = manage ( new Gtk::Dialog() );
dialog->set_title("Add Text");

Gtk::Entry entry;

entry.set_activates_default(true);
entry.set_max_length(50);
entry.set_text("hello world");
entry.select_region(0, entry.get_text_length());

dialog->add(entry);
dialog->show();

This code shows an empty dialog box. On using show_all() or show_all_children() , nothing happens, not even an empty dialog box shows up.

And I get the following warning in all cases:

Gtk-WARNING **: Attempting to add a widget with type gtkmm__GtkEntry to a gtkmm__GtkDialog, but as a GtkBin subclass a gtkmm__GtkDialog can only contain one widget at a time; it already contains a widget of type GtkVBox

Help me resolve this issue.

The Gtk::Dialog already has a VBox added to it. Looking at the source file of Gtk::Dialog class, I found get_vbox() function. I had to access the VBox to add further components to the dialog.

dialog->get_vbox()->pack_start(*entry, Gtk::PACK_SHRINK);
dialog->set_text("hello world");

dialog->set_size_request(200,100);
dialog->show_all();

And it works all fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM