Re: change font in treeview



2011-12-29 02:32, kiet tran skrev:
Hi,

Could any1 show me how to change font and its size for each row in TreeModel.

cheers,

Kiet Tran

The TreeModel stores the data, the TreeView shows the data. The TreeView gets help from CellRenderers, such as CellRendererText. What you need to do is change some properties of a CellRenderer.

I haven't tried this myself. Some details may be wrong, but basically something like this:

// Get a pointer to the CellRenderer in the column you want to change.
Gtk::CellRenderer* cellRenderer = m_TreeView.get_column_cell_renderer(iViewColumn);
// Assume you expect it to be a CellRendererText.
Gtk::CellRendererText* cellRendererText = dynamic_cast<CellRendererText*>(cellRenderer);
if (cellRendererText)
{
  cellRendererText->property_font() = "MyExcellentFont";
  cellRendererText->property_size() = 20;
}

If you want to specify properties for individual cells (not just whole columns), I think you should use attributes in TreeViewColumn's CellLayout interface. Your TreeModel must contain one extra column for each attribute you specify.

Gtk::TreeViewColumn* treeViewColumn = m_TreeView.get_column(iViewColumn);
Gtk::CellRenderer* cellRenderer = m_TreeView.get_column_cell_renderer(iViewColumn);
// Assume you expect it to be a CellRendererText.
Gtk::CellRendererText* cellRendererText = dynamic_cast<CellRendererText*>(cellRenderer);
if (cellRendererText)
{
treeViewColumn->add_attribute(cellRendererText->property_font(), m_Columns.m_font); treeViewColumn->add_attribute(cellRendererText->property_size(), m_Columns.m_size);
}

Have you studied the TreeView widget chapter in the gtkmm tutorial?
http://developer.gnome.org/gtkmm-tutorial/stable/chapter-treeview.html.en

Kjell



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