You are not logged in.

#1 2005-03-26 21:38:29

sickboy
Member
Registered: 2004-10-29
Posts: 18

gtkmm combobox problem

This is driving me nuts !

I am trying to figure out how you get the text from the selection of a combobox (note: not combo entry box)

I have populated the combobox Ok by attaching a liststore to it :

    // set up model for combo box
    m_refComboModel = Gtk::ListStore::create(m_Combo);
    viewComboBox->set_model(m_refComboModel);
    viewComboBox->pack_start(m_Combo.view_col);    
    
    // Set the 3 default values for the combobox
    Gtk::TreeModel::Row row = *(m_refComboModel->append());
    row[m_Combo.view_col] = "item 1";
    
    row = *(m_refComboModel->append());
    row[m_Combo.view_col] = "item 2";
    
    row = *(m_refComboModel->append());
    row[m_Combo.view_col] = "item 3";

I have a signal that is generated if the user make a selection from the combobox in the following function  :

//---------------------------------------------
// User has selcted new positon in combo box
//--------------------------------------------
void window1::on_viewComboBox_changed()
{
    // get the current selection from the combobox
    // to do ........................................................
    TreeModel::iterator i = viewComboBox->get_active();
}

tried variuos ways but I can not figure out how to get the item selected.

get_active always returns 1.

Can anybody show me the light (preferably with an example)

Offline

#2 2005-03-26 21:51:50

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: gtkmm combobox problem

i think you want to use:

Gtk::TreeIter it;
viewComboBox->get_active_iter(it);

Offline

#3 2005-03-26 22:01:33

sickboy
Member
Registered: 2004-10-29
Posts: 18

Re: gtkmm combobox problem

No the combobox does not have a get_active_iter method - so this just gives a compile error.

but thanks for the quick reply

Offline

#4 2005-03-26 22:43:18

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: gtkmm combobox problem

ah... it's been a while since I touched the gtkmm stuff... I actually thing the *iter methods were before gtkmm was known as gtkmm... I'm not really sure

Offline

#5 2005-03-28 11:27:32

zeppelin
Member
From: Athens, Greece
Registered: 2004-03-05
Posts: 807
Website

Re: gtkmm combobox problem

PyGTK says:
gtk.ComboBox.get_active_text

    def get_active_text()

Returns :    The currently active text.
Note

This method is available in PyGTK 2.6 and above.

The get_active_text() method returns the currently active string or None if no entry is selected. Note that you can only use this function with combo boxes constructed with the gtk.combo_box_new_text() function.

so either wait for GTKmm to wrap the GTK 2.6 smile or switch to Python or maybe use
get_active_row_number      ?

but does on_viewComboBox_changed() get executed?
if you get the iter, do you get the value in the iter?
Good Luck, if you want write a small executable code to reproduce your pb so we can help better

Offline

#6 2005-03-29 21:30:19

sickboy
Member
Registered: 2004-10-29
Posts: 18

Re: gtkmm combobox problem

Ahhh I can use the specialized class ComboBoxText then I can use the get_active_text method. You can't seem to insert his widget using Glade so I did not realize this at first.

Offline

Board footer

Powered by FluxBB