I want to create a table of laptops. One of the column is the type of CPU, so I want to only allow user to select one from a list of given CPUs. I made something like this:

Firstly, a ListStore of CPUs, and a ListStore of the big table, defined in glade:
...... <object class="GtkTreeView" id="ModelTable"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="model">ModelListStore</property> <child internal-child="selection"> <object class="GtkTreeSelection" id="treeview-selection1 +"/> </child> </object> ...... <object class="GtkListStore" id="CPUListStore"> <columns> <!-- column-name col_cpu --> <column type="gchararray"/> </columns> </object> <object class="GtkListStore" id="ModelListStore"> <columns> <!-- column-name name --> <column type="gchararray"/> <!-- column-name cpu_name --> <column type="gchararray"/> <!-- column-name gpu_name --> <column type="gchararray"/> <!-- column-name mem_sz --> <column type="gfloat"/> <!-- column-name mem_freq --> <column type="gint"/> <!-- column-name disk_sz --> <column type="gint"/> <!-- column-name disk_rot --> <column type="gint"/> <!-- column-name screen_sz --> <column type="gfloat"/> <!-- column-name price --> <column type="gfloat"/> </columns> </object>
then create the GUI in perl:
# this is the table $model_table = $builder->get_object('ModelTable'); # cell renderer # 0th column of "CPUListStore" is used, as it has only that column. my $renderer_table_cpu = Gtk2::CellRendererCombo->new; $renderer_table_cpu->set(model=>$builder->get_object('CPUListStore')); $renderer_table_cpu->set(text_column=>0); $renderer_table_cpu->set(has_entry=>TRUE); # the TreeViewColumn # it corresponds to the COL_CPU_NAME column of the big table my $col_cpu = Gtk2::TreeViewColumn->new; $col_cpu->pack_start($renderer_table_cpu,TRUE); $col_cpu->add_attribute($renderer_table_cpu,'text',COL_CPU_NAME);

The problem is: when I change the value in combo, the table won't get modified. It seems the change of selection in the combobox does not correctly passed to the model of table. So how to use CellRendererCombo correctly? Thanks a lot!


In reply to Hwo to correctly use Gtk2::CellRendererCombo? by llancet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.