Re: [gtkmm] Listview Newbie Question



Thank you. I was making that call in my initialize function not the
on_changed one. So I moved it to the on_changed callback function and
voila! It works! 

Thanks again.

Art


On Sun, 2003-10-26 at 11:18, karim bernardet wrote:
> try this
> 
> Makefile :
> 
> all : main
> 
> 
> examplewindow.o : examplewindow.cc
>    g++ -c examplewindow.cc `pkg-config --cflags gtkmm-2.0`
> 
> 
> main.o : main.cpp
>    g++ -c main.cpp `pkg-config --cflags gtkmm-2.0`
> 
> main : main.o examplewindow.o
>    g++ main.o examplewindow.o -o main `pkg-config --cflags --libs 
> gtkmm-2.0`
> 
> main.cpp :
> 
> #include <gtkmm/main.h>
> #include "examplewindow.h"
> 
> int main(int argc, char *argv[])
> {
>  Gtk::Main kit(argc, argv);
> 
>  ExampleWindow window;
>  Gtk::Main::run(window);
> 
>  return 0;
> }
> 
> examplewindow.cc :
> 
> 
> #include <iostream>
> #include "examplewindow.h"
> 
> ExampleWindow::ExampleWindow()
> : m_Button_Quit("Quit")
> {
>  set_title("Gtk::TreeView (TreeStore) example");
>  set_border_width(5);
>  set_default_size(400, 200);
> 
> 
>  add(m_VBox);
> 
>  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
>  m_ScrolledWindow.add(m_TreeView);
> 
>  //Only show the scrollbars when they are necessary:
>  m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
> 
>  m_VBox.pack_start(m_ScrolledWindow);
>  m_VBox.pack_start(m_ButtonBox, Gtk::PACK_SHRINK);
> 
>  m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK);
>  m_ButtonBox.set_border_width(5);
>  m_ButtonBox.set_layout(Gtk::BUTTONBOX_END);
>  m_Button_Quit.signal_clicked().connect( SigC::slot(*this, 
> &ExampleWindow::on_button_quit) );
> 
>  //Create the Tree model:
>  m_refTreeModel = Gtk::TreeStore::create(m_Columns);
>  m_TreeView.set_model(m_refTreeModel);
> 
> 
> 
>  // Glib::RefPtr<Gtk::TreeSelection> selection;
> 
> selection =  m_TreeView.get_selection();
>  selection->set_mode(Gtk::SELECTION_MULTIPLE);
> 
>  //   selection->selected_foreach(SigC::slot(*this, 
> &ExampleWindow::selected_row_callback) );
> 
>     selection->signal_changed().connect(SigC::slot(*this, 
> &ExampleWindow::on_selection_changed));
> 
> 
> 
>  //Fill the TreeView's model
>  Gtk::TreeModel::Row row = *(m_refTreeModel->append());
>  row[m_Columns.m_col_id] = 1;
>  row[m_Columns.m_col_name] = "Billy Bob";
> 
> 
>  row = *(m_refTreeModel->append());
>  row[m_Columns.m_col_id] = 2;
>  row[m_Columns.m_col_name] = "Joey Jojo";
> 
> 
>  row = *(m_refTreeModel->append());
>  row[m_Columns.m_col_id] = 3;
>  row[m_Columns.m_col_name] = "Rob McRoberts";
> 
> 
>  //Add the TreeView's view columns:
>  m_TreeView.append_column("ID", m_Columns.m_col_id);
>  m_TreeView.append_column("Name", m_Columns.m_col_name);
> 
>  show_all_children();
> }
> 
> ExampleWindow::~ExampleWindow()
> {
> }
> 
> void ExampleWindow::on_button_quit()
> {
>  hide();
> }
> *
> 
> void ExampleWindow::selected_row_callback(const 
> Gtk::TreeModel::iterator& iter)
> {
>  std::cout << "selected_row_callback" << std::endl;
>  Gtk::TreeModel::Row row = *iter;
>  //Do something with the row.
> }
> 
> void ExampleWindow::on_selection_changed()
> {
>  std::cout << "on_selection_changed" << std::endl;
>  selection->selected_foreach(SigC::slot(*this, 
> &ExampleWindow::selected_row_callback));
> }*
> 
> 
> examplewindow.h :
> 
> 
> #ifndef GTKMM_EXAMPLEWINDOW_H
> #define GTKMM_EXAMPLEWINDOW_H
> 
> #include <gtkmm.h>
> 
> class ExampleWindow : public Gtk::Window
> {
> public:
>  ExampleWindow();
>  virtual ~ExampleWindow();
> 
> protected:
>  //Signal handlers:
>  virtual void on_button_quit();
> 
>  void selected_row_callback(const Gtk::TreeModel::iterator& iter);
>  void on_selection_changed();
> 
>  //Tree model columns:
>  class ModelColumns : public Gtk::TreeModel::ColumnRecord
>  {
>  public:
> 
>    ModelColumns()
>    { add(m_col_id); add(m_col_name); }
> 
>    Gtk::TreeModelColumn<int> m_col_id;
>    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
>  };
> 
>  ModelColumns m_Columns;
> 
>  //Child widgets:
>  Gtk::VBox m_VBox;
> 
>  Gtk::ScrolledWindow m_ScrolledWindow;
>  Gtk::TreeView m_TreeView;
>  Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;
> Glib::RefPtr<Gtk::TreeSelection> selection;
> 
>  Gtk::HButtonBox m_ButtonBox;
>  Gtk::Button m_Button_Quit;
> };
> 
> #endif //GTKMM_EXAMPLEWINDOW_H
> 
> 
> 
> 
> 
> 
> Art Schwalbenberg wrote:
> 
> >Greetings.
> >
> >    I'm new to GTK and Gtkmm development. My question is this:
> >
> >What is the missing piece of the puzzle concerning multiple selection?
> >
> >I've implemented callback required for the following code
> >
> >   AvailableFiles->get_selection()->selected_foreach( 
> >		SigC::slot(*this, &MainWindow::AvailableSelectedRows) );
> >   AvailableFiles->get_selection()->signal_changed().connect(
> >SigC::slot(*this, &MainWindow::AvailableFilesCursorChanged) );
> >
> >Well the signal_changed() works well enough but I just don't know how
> >get the callback function (AvailableSelectedRows) supplied to
> >selected_foreach to fire so I can actually get the rows that are
> >selected.
> >
> >If I'm missing something obvious I apologize in advance.
> >
> >  
> >
> 
> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list




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