Problem enabling Pango markup in a TreeView



Hi everyone,

I want to use Pango markup in text in a TreeView.

This seems to have been covered before
(http://www.nabble.com/Formating-text-in-treeview-t3119030.html) but I
am unclear on how to use it.

The twist here is that I am trying to enable markup on a treeview
created via libglademm.

My test code looks like this (originally based on the TreeView example code):

class PropertiesEditor
{
	public:
		PropertiesEditor(Gtk::TreeView *treeView);
		~PropertiesEditor() {}

	private:
		class PropertiesModelColumns : public Gtk::TreeModel::ColumnRecord
		{
			public:
				PropertiesModelColumns() { add(m_PropName); add(m_PropValue); }

				Gtk::TreeModelColumn<Glib::ustring> m_PropName;
				Gtk::TreeModelColumn<Glib::ustring> m_PropValue;
		};

		Gtk::TreeView *m_TreeView;

		PropertiesModelColumns m_PropertiesColumns;
		Glib::RefPtr<Gtk::TreeStore> m_PropertiesTreeModel;
};


PropertiesEditor::PropertiesEditor(Gtk::TreeView *treeView)
	: m_TreeView(treeView)
{
	// Create the Tree model
	m_PropertiesTreeModel = Gtk::TreeStore::create(m_PropertiesColumns);
	m_TreeView->set_model(m_PropertiesTreeModel);

	// Fill the TreeView's model FIXME
	Gtk::TreeModel::Row row = *(m_PropertiesTreeModel->append());
	row[m_PropertiesColumns.m_PropName] = "<b>Speed</b>";
	row[m_PropertiesColumns.m_PropValue] = "";

	Gtk::TreeModel::Row childrow =
*(m_PropertiesTreeModel->append(row.children()));
	childrow[m_PropertiesColumns.m_PropName] = "Units";
	childrow[m_PropertiesColumns.m_PropValue] = "ms<sup>-1</sup>";

	// Add the Properties TreeView's view columns
	m_TreeView->append_column("Property", m_PropertiesColumns.m_PropName);
	m_TreeView->append_column("Value", m_PropertiesColumns.m_PropValue);

	// Enable Pango markup for both columns, and make columns resizeable
	Gtk::TreeViewColumn *col = m_TreeView->get_column(0);
	Gtk::CellRendererText *renderer = dynamic_cast<Gtk::CellRendererText*>(
			col->get_first_cell_renderer());
	col->add_attribute(renderer->property_markup(),
m_PropertiesColumns.m_PropName);
	col->set_resizable(true);

	col = m_TreeView->get_column(1);
	renderer = dynamic_cast<Gtk::CellRendererText*>(col->get_first_cell_renderer());
	col->add_attribute(renderer->property_markup(),
m_PropertiesColumns.m_PropValue);
	col->set_resizable(true);
}

where the PropertiesEditor constructor is passed a pointer to the
libglademm-created TreeView. Everything other than enabling the markup
appears to work correctly.

Based on the comments made in the previous thread, I think I might
need to enable markup on a CellRenderText and then make the columns
manually (passing them the instance of the renderer), rather than
using TreeView::append_column, and then enabling markup after the
fact, but I can't see how to do that.

As you might be able to tell, I am somewhat new to gtkmm, so any
general comments of style and structure will always be appreciated!

Thanks in anticipation,
Hugo Vincent.



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