Gtkmm::View[2]
Specifying CellRenderer details
The default CellRenderers and their default behaviour will normally suffice, but you might occasionally need finer control. For instance, this example code from demos/gtk-demo/example_treestore.cc, manually constructs a Gtk::CellRenderer widget and instructs it to render the data from various model columns through various aspects of its appearance.
Gtk::CellRendererToggle* pRenderer = Gtk::manage( new Gtk::CellRendererToggle() );
int cols_count = m_TreeView.append_column("Alex", *pRenderer);
Gtk::TreeViewColumn* pColumn = m_TreeView.get_column(cols_count-1);
if(pColumn)
{
pColumn->add_attribute(pRenderer->property_active(),
m_columns.alex);
pColumn->add_attribute(pRenderer->property_visible(),
m_columns.visible);
pColumn->add_attribute(pRenderer->property_activatable(),
m_columns.world);
You can also connect to CellRenderer signals to detect user actions. For instance:
Gtk::CellRendererToggle* pRenderer =
Gtk::manage( new Gtk::CellRendererToggle() );
pRenderer->signal_toggled().connect(
sigc::bind( sigc::mem_fun(*this,
&Example_TreeView_TreeStore::on_cell_toggled), m_columns.dave)
);
自己新建的Cell Render显然也是从Model中读取数据,而Model的Column就是制定从哪个中读取数据,充当桥梁作用。依赖的所有数据都来源于Model。继而Model Column大约的作用仅仅是用自己的成员变量当做标志位。也就是可以在两者之间进行连接。
而自己做出的CellRenderer可以用add_attrbute来把本身的某个property同model中的某列对应。
实际上相当于model的对象做出一张数据表,不需要考虑行对应问题,只需要考虑列对应问题就好了,而列标识符就为一个Model Column的实例。而View Column则是一个Sensor,可以定制其Sensor,Model中的哪一个列。
估计还有的东西就是响应相应的CellRenderer的signal和定制行相关的东西,主要是selection和filter。
浙公网安备 33010602011771号