Re: Add tabs to Notebook at runtime, loaded from .glade file?

I understand your problem to be that you have a set of widgets, and
you want to instantiate multiple Gtk::Notebook tabs, each containing
that same set of widgets, and that you've had to generate and read
multiple identical .glade files (each defining a Gtk::Window
containing the widget set) to get it working.

Yes, precisely.

If that accurately reflects where you're at, then you're now creating
a new Gtk:Builder instance each time you read one of those
multiple .glade files, and it's that new instance-per-tab that has
made things work. You can go back to using just one .glade file, as
long as you continue to create a new Gtk::Builder instance every time
you re-read it for a new tab.

From what I have read, putting everything into the one file and
creating a new Gtk::Builder instance on each new tab would also cause
the whole .glade file to be parsed every time.  This would apparently
create potentially dozens of unneeded windows/widgets, then after
selecting the widget for the new tab, the rest of them would be
destroyed again.  Is this correct?

As I'm so new to GTK, I'm just trying to work out the pros and cons of
single vs multiple .glade files.

You can also dispense with the Gtk::Window if you make your Gtk::Box
a top-level widget (in glade, right-click the Gtk::Box icon in the
widget pane and select "Add widget as toplevel"). You can then lose
the reparent (), and you can prepend_page (), insert_page (), or
append_page () the Gtk::Box directly. Also, all of these tab-addition
functions have forms that allow specification of the tab title.

Aha!!  That's the step I was missing.  After making the Gtk::Box a
top-level widget in Glade, I am able to retrieve it and add it to the
Notebook without any problem, even using the append_page() variant that
lets me supply the tab's title.

Many thanks for solving my problem!


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]