The only way i can see is that you:

1) Acquire information about the spacings used inside ComboBox

2) Use a Pango::Layout created for the widget in question (the treeview)
(See Gtk::Widget::create_pango_layout()) and go through all the strings,
render them with the Layout and acquire the size, keeping the highest width
3) Sum it up with the spacings, if any

That's a little berserk-ish but there really is no other way.
As an improvement one could acquire the actual CellRendererText contained
_in_ the ComboBox of the CellRendererCombo, and use it to render the
layouts, since it's also what effectively renders the texts and it would
take already unusual properties set to it by the CellRendererCombo when
setting it up (i bet it's just a CellRendererText inside though).

2008/4/7, Tiberius Duluman <[EMAIL PROTECTED]>:
>
> Hello,
>
> I have the following question about a CellRenderCombo:
> when a user pops up the item list of the renderer,
> some longer items are not rendered entirely because
> they don't have enough space in the list.
> How can I expand the column to the minimum size required
> for the items in the list to be entirely displayed.
>
> For example, run the application below and click on a
> row in second column. The combo pops up, but the text
> displayed is "sho" and "som".
> In this example, the items of the combo are static,
> but in my application, the items are dynamically.
>
>
> #include <gtkmm.h>
>
> class ExampleWindow : public Gtk::Window
> {
> public:
>     ExampleWindow();
>     virtual ~ExampleWindow() {}
>
> protected:
>     void Changed(
>         const Glib::ustring &sPath, const Glib::ustring &text);
>
>     class ModelColumns : public Gtk::TreeModel::ColumnRecord
>     {
>     public:
>         ModelColumns() { add(x); add(m_col_itemchosen); }
>         Gtk::TreeModelColumn<Glib::ustring> x;
>         Gtk::TreeModelColumn<Glib::ustring> m_col_itemchosen;
>     };
>     ModelColumns m_Columns;
>
>     class ModelColumnsCombo : public Gtk::TreeModel::ColumnRecord
>     {
>     public:
>         ModelColumnsCombo() { add(m_col_choice); }
>         Gtk::TreeModelColumn<Glib::ustring> m_col_choice; //The values
> from which the user may choose.
>     };
>     ModelColumnsCombo m_ColumnsCombo;
>
>     Gtk::TreeView m_TreeView;
>     Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
>     Glib::RefPtr<Gtk::ListStore> m_refTreeModelCombo1;
>     Gtk::CellRendererCombo renderer;
> };
>
>
> ExampleWindow::ExampleWindow()
> {
>     set_title("Gtk::TreeView (ListStore) example");
>     set_border_width(5);
>     set_default_size(400, 200);
>     add(m_TreeView);
>
>     m_refTreeModelCombo1 = Gtk::ListStore::create(m_ColumnsCombo);
>     (*m_refTreeModelCombo1->append())[m_ColumnsCombo.m_col_choice] =
> "short";
>     (*m_refTreeModelCombo1->append())[m_ColumnsCombo.m_col_choice] =
> "something longer";
>
>     m_refTreeModel = Gtk::ListStore::create(m_Columns);
>     m_TreeView.set_model(m_refTreeModel);
>     (*m_refTreeModel->append())[m_Columns.m_col_itemchosen] = "short";
>     (*m_refTreeModel->append())[m_Columns.m_col_itemchosen] = "short";
>     (*m_refTreeModel->append())[m_Columns.m_col_itemchosen] = "short";
>
>     //Create a Combo CellRenderer, instead of the default Text
> CellRenderer:
>     Gtk::TreeView::Column &columnX =
> *m_TreeView.get_column(m_TreeView.append_column("X", m_Columns.x) - 1);
>     columnX.set_expand();
>     Gtk::TreeView::Column &column =
> *m_TreeView.get_column(m_TreeView.append_column("Selected", renderer) -
> 1);
>
>     column.add_attribute(renderer.property_text(),
> m_Columns.m_col_itemchosen);
>
>     renderer.property_has_entry() = false;
>     renderer.property_model() = m_refTreeModelCombo1;
>     renderer.property_text_column() = 0;
>     renderer.property_editable() = true;
>
>     renderer.signal_edited().connect(
>         sigc::mem_fun(*this, &ExampleWindow::Changed));
>
>     show_all_children();
> }
>
> void ExampleWindow::Changed(
>     const Glib::ustring &sPath, const Glib::ustring &text)
> {
>     Gtk::TreePath path(sPath);
>     Gtk::TreeModel::iterator row = m_refTreeModel->get_iter(path);
>     if (row)
>         (*row)[m_Columns.m_col_itemchosen] = text;
> }
>
> int main(int argc, char *argv[])
> {
>     Gtk::Main kit(argc, argv);
>
>     ExampleWindow window;
>     Gtk::Main::run(window); //Shows the window and returns when it is
> closed.
>
>     return 0;
> }
>
> _______________________________________________
> gtkmm-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to