2011-12-30 11 views
2

Gtkmmでは、ListStoreを使ってGtk TreeViewを作成し、リスト内の列の1つをComboBoxTextにしたいと考えています。しかし、私はそれを行う方法を把握していないようです。ComboBoxをTreeView列に追加するにはどうすればよいですか?

class PlayerListColumns : public Gtk::TreeModelColumnRecord 
{ 
public: 

    PlayerListColumns() 
    { add(name); add(team);} 

    TreeModelColumn<string> name; 
    TreeModelColumn<ComboBoxText*> team; 
} 

そして、TreeViewコントロール(player_list_viewオブジェクト)

PlayerListColumns *columns = new PlayerListColumns(); 
Glib::RefPtr<ListStore> refListStore = ListStore::create(*columns); 
player_list_view->set_model(refListStore); 

ComboBoxText *box = manage(new ComboBoxText()); 
box->append("Blah"); 
box->append("Blah"); 
box->append("Blah"); 

TreeModel::Row row = *(refListStore->append()); 
row[columns->name] = "My Name"; 
row[columns->team] = box; 

列 "名前" がうまく現れ、ないコンボボックスを設定するとき:

は、私は現在のようなルックスを持ってどのような。私はほぼ単に列の型としてコンボボックスへのポインタを持っていることは間違っていますが、私はそれがどのようになっているのかわかりません。私はGTK警告が表示されますか:

のGLib-GObjectの-WARNING **:プロパティtext' of type gchararrayを設定することができない '`型の値からGtkComboBoxText' の小さなビットから(示すように思わ

グーグル)は、非基本型のためのデフォルトのレンダラーは存在しないということです。しかし、問題があれば、私はそれを設定する方法の例を見つけることができませんでした。すべてのチュートリアルでは、プリミティブデータ型のTreeViewのみが表示されます。

誰でもComboBoxをTreeViewに配置する方法を知っていますか?

答えて

3

さて、私は100%の作業、それをもらっていないが、この例のクラスは正しい軌道に乗ってあなたを取得する必要があります: http://svn.gnome.org/svn/gtkmm-documentation/trunk/examples/book/treeview/combo_renderer/

基本的にあなたが列クラスにGtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> >を追加する必要があると保持するためGtk::TreeModelColumn<string>選択されたデータ私はGtk::CellRendererCombo*を使用しての線に沿って何かがあなたのPlayerListColumns

に行くための方法だと思い

//manually created column for the tree view 
Gtk::TreeViewColumn* pCol = Gtk::manage(new Gtk::TreeViewColumn("Choose")); 

//the combobox cell renderer 
Gtk::CellRendererCombo* comboCell = Gtk::manage(new Gtk::CellRendererCombo); 

//pack the cell renderer into the column 
pCol->pack_start(*comboCell); 

//append the column to the tree view 
treeView->append_column(*pCol); 

//this sets the properties of the combobox and cell 
//my gtkmm seems to be set for Glibmm properties 
#ifdef GLIBMM_PROPERTIES_ENABLED 
    pCol->add_attribute(comboCell->property_text(), columns->team); 

    //this is needed because you can't use the ComboBoxText shortcut 
    // you have to create a liststore and fill it with your strings separately 
    // from your main model 
    pCol->add_attribute(comboCell->property_model(), columns->teams); 

    comboCell->property_text_column() = 0; 
    comboCell->property_editable() = true; 
#else 
    pCol->add_attribute(*comboCell, "text", columns->team); 
    pCol->add_attribute(*comboCell, "model", columns->teams); 
    comboCell->set_property(text_column:, 0); 
    comboCell->set_property("editable", true); 
#endif 

//connect a signal so you can set the selected option back into the model 
//you can just have a column that is not added to the view if you want 
comboCell->signal_edited() 
    .connect(sigc::mem_fun(*this,&ComboWindow::on_combo_choice_changed)); 

EDIT

上:

その後、列コンボボックスを作るために、あなたが追加する必要があります

http://developer.gnome.org/gtkmm/stable/classGtk_1_1CellRendererCombo.html

(私はまだ作業テストを行っていないが、私はからアイデアを得た: http://developer.gnome.org/gtkmm-tutorial/unstable/sec-treeview.html.en#treeview-cellrenderer-details

関連する問題