Problem With Gtk::CellLayout and Gtk::TreeModel
- From: Jim Orcheson <jim va3hj ca>
- To: gtkmm-list gnome org
- Subject: Problem With Gtk::CellLayout and Gtk::TreeModel
- Date: Sun, 23 May 2010 13:27:53 -0400
I am attempting to create a font family selector based on ComboBoxText.
I want to display the font family names in the same family as the name
so that users have an idea of what their text will look upon selecting
that font. However, all items in the combobox display in the same
(default) text.
I found a hint in the archives in a posting with the subject
"Gtk::CellLayout & Gtk::TreeModel
(http://mail.gnome.org/archives/gtkmm-list/2006-February/msg00052.html
and
http://mail.gnome.org/archives/gtkmm-list/2006-February/msg00053.html)
which dealt with setting items sensitive. I tried the same thing to set
font family for each combobox item, but cannot get it to compile. Here
is my class:
#include <set>
#include <gtkmm.h>
typedef std::set<Glib::ustring> FontSet;
class FontSelector : public Gtk::ComboBoxText {
public:
FontSelector() {
// add colummns to model
col_records.add(col1);
refStore = Gtk::ListStore::create(col_records);
set_model(refStore);
// show font family text in the font family
pack_start(renderer, true);
add_attribute(renderer, "family", 0);
// compile error with the following statement
set_cell_data_func(renderer, set_family);
// add the font family names to the combobox
Glib::RefPtr<Pango::Context> pc = this->get_pango_context();
if(pc) {
FontSet fonts;
Glib::ArrayHandle<Glib::RefPtr<Pango::FontFamily> > families
= pc->list_families();
for(Glib::ArrayHandle<Glib::RefPtr<Pango::FontFamily>
>::iterator it = families.begin(); it < families.end(); it++) {
fonts.insert((*it)->get_name());
}
for(FontSet::iterator it = fonts.begin(); it != fonts.end();
it++) {
addrow(*it);
}
}
}
private:
Gtk::TreeModelColumnRecord col_records;
Glib::RefPtr<Gtk::ListStore> refStore;
Gtk::TreeModelColumn<Glib::ustring> col1;
Gtk::CellRendererText renderer;
void addrow(Glib::ustring family) {
Gtk::ListStore::iterator it = refStore->append();
Gtk::ListStore::Row row = *it;
row[col1] = family;
}
void set_family(Gtk::TreeIter iter) {
Gtk::TreeModel::Row row = *iter;
Glib::ustring family = row[col1];
renderer.property_family() = family;
}
};
Now the problem:
1. As the code sits, when I try to compile code that references the
FontSelector constructor, I get the following error:
error: no matching function for call to
'FontSelector::set_cell_data_func(Gtk::CellRendererText&, <unresolved
overloaded function type>)'
note: candidates are: void
Gtk::CellLayout::set_cell_data_func(Gtk::CellRenderer&, const
sigc::slot<void, const Gtk::TreeIter&, sigc::nil, sigc::nil, sigc::nil,
sigc::nil, sigc::nil, sigc::nil>&)
2. If I change the problem line to:
sigc::slot<void, Gtk::TreeIter> s =
sigc::ptr_fun(&FontSelector::set_family);
set_cell_data_func(renderer, s);
then I get the following compiler error on the first line:
error: no matching function for call to 'ptr_fun(void
(FontSelector::*)(Gtk::TreeIter))'
Having followed the code as outlined in the archived postings mentioned
above, I am at a loss as to what little or great thing that I am doing
wrong. Any help is appreciated.
Jim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]