Re: Glade & ComboBoxEntry



Thanks Christoph, that was a good help and exactly what I want to do, but I'm still struggling with the glade side of things. You see I want to define columns and rows in the glade file but I just can't make that work. So in the hope someone can see what I'm doing wrong I attach a .tar containing my simplified .glade and .cc file.

Basically it's this bit I want out of the code into the XML:

// Tree model columns: but I don't want this in the code
// I think glade can put it in the XML
struct ModelColumns : Gtk::TreeModel::ColumnRecord {
ModelColumns() {
add(m_col_name);
}
Gtk::TreeModelColumn<Glib::ustring> m_col_name;
} m_Columns;

and this bit
m_refTreeModel = Gtk::ListStore::create(m_Columns);
pComboBoxEntry1->set_model(m_refTreeModel);

// It be nice to put initial rows in the glade file too
// although I do want to add the ones that the user creates
Gtk::TreeModel::Row row = *(m_refTreeModel->append());
row[m_Columns.m_col_name] = "Option 1";

row = *(m_refTreeModel->append());
row[m_Columns.m_col_name] = "Option 2";

row = *(m_refTreeModel->append());
row[m_Columns.m_col_name] = "Option 3";

   pComboBoxEntry1->set_text_column(m_Columns.m_col_name);

Thanks for all and any insights :)

On 19 September 2010 11:03, Christoph Nikic <c nikic gmx de> wrote:
Hi,

create a combox, and a liststore in glade (assign the liststore to the
combobox entry.

Then in c++, if you use Gtk::Builder (instead of libglade):

Glib::RefPtr<Gtk::Builder> b =
Gtk::Builder::create_from_file("simple.glade")

m_liststore = dynamic_cast<Gtk::Liststore>
b->get_object("liststore_name");

Gtk::ComboBoxEntry *combo;
b->get_widget("combox_name", combo);

combo->signal_changed().connect(sigc::mem_fun(this,
&App::combo_changed));

void App::combo_changed() {
Gtk::TreeModel::Row row = *(m_liststore->append());
row.set_value(0, combo->get_active_text());
}

well i think almost like this ;)

best regards

Am Sonntag, den 19.09.2010, 10:32 +1200 schrieb Chris Scaife:
> I'm new to gtkmm and glade and trying to make my second gui app with
> it. Alas getting confused by all the different tutorials and
> explanations out there on the web.
>
>
> What I want to do is have something like a ComboBoxEntry widget that
> has a menu of options (utf8 character strings). Preferably, I just
> want to define these in the XML file that Glade produces.
>
>
> The idea is that the user can select one and edit it as he/she wishes.
> Then that edited value gets used bt the program when the Enter key is
> pressed, or perhaps by clicking a button somewhere.
>
>
> If anyone can explain what I need, or can tell me of a web site that
> shows how to do this (using glade and gtkmm with C++) it be much
> appreciated :)
>
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list


Attachment: combo.tar
Description: Unix tar archive



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