2016-06-02 32 views
0

Ich füge Gtk::Entry zu Gtk::Dialog hinzu.Hinzufügen von Gtk :: Eintrag zu 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(); 

Dieser Code zeigt ein leeres Dialogfeld an. Bei der Verwendung von oder show_all_children() passiert nichts, nicht einmal ein leeres Dialogfeld wird angezeigt.

Und ich bekomme die folgende Warnung in allen Fällen:

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

Hilf mir, dieses Problem zu beheben.

Antwort

1

Der Gtk::Dialog hat bereits eine VBox hinzugefügt. Mit Blick auf die Quelldatei der Gtk :: Dialog-Klasse habe ich get_vbox() Funktion gefunden. Ich musste auf die VBox zugreifen, um weitere Komponenten zum Dialog hinzuzufügen.

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

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

Und es funktioniert alles in Ordnung.