Gtk::CellRendererCombo
- From: Tiberius Duluman <tiberius duluman gmail com>
- To: gtkmm-list gnome org
- Subject: Gtk::CellRendererCombo
- Date: Mon, 07 Apr 2008 23:20:05 +0300
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]