Re: [gtkmm] treeview single click signal



I dont think I undertand you fully....
I tried the following - 
I created a Glib::RefPtr<Gtk::TreeSelection> object
and pointed it to a TreeView.get_selection().

I am trying to add a signal handler to the
TreeSelection object but I get the following error.

main.cc: In constructor `findPanel::findPanel()':
main.cc:72: no matching function for call to
`Glib::SignalProxy0<void>::connect (SigC::Slot1<void,
findPanel&>)'
/usr/include/gtkmm-2.0/glibmm/signalproxy.h:113:
candidates are: 
   SigC::Connection
Glib::SignalProxy0<R>::connect(const SigC::Slot0<R>&,
bool = true) [with R = void]

I have attached my code below...

My goal still is to detect which row was clicked (with
single click of mouse) in a TreeView/ListStore .

Someone suggested creating a TreeSelection and using
its signal_changed() function. I have run into more
problems doing this...
Yada

--code begins
main.cc:
using namespace std;

#include <iostream>
#include <string>
#include <gtkmm/main.h>
#include <gtkmm/main.h>
#include <gdk/gdkkeysyms.h>
#include <gtkmm/treeselection.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treeview.h>
#include <gtkmm/liststore.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/window.h>


class findModelColumns : public
Gtk::TreeModel::ColumnRecord
{
  public:
    Gtk::TreeModelColumn<int> colNumber;
    Gtk::TreeModelColumn<Glib::ustring> foo1ColText;
    Gtk::TreeModelColumn<Glib::ustring> foo2ColText;
    Gtk::TreeModelColumn<Glib::ustring> foo3ColText;

    /*methods*/
    findModelColumns();
    ~findModelColumns();
};

class findPanel : public Gtk::Window {
  public:
    Gtk::ScrolledWindow findScrolledWindow;
    /* a Vertical container to split the window into
two halves */

    void clear();
    findPanel();
    ~findPanel();

    virtual void on_selection_changed();

  protected:
    Gtk::TreeView findTreeView;
    findModelColumns findColumns;
    Glib::RefPtr<Gtk::ListStore> findTreeModelPtr;
    Glib::RefPtr<Gtk::TreeSelection> treeSel;
};

int main(int argc, char *argv[]) {
  
  Gtk::Main kit(argc, argv);

  findPanel mainWin;
  Gtk::Main::run(mainWin);
  return 0;
}


findPanel::findPanel() {
  /*create the tree model*/
  findTreeModelPtr =
Gtk::ListStore::create(findColumns);
  findTreeView.set_model(findTreeModelPtr);
  Gtk::TreeModel::iterator iter =
findTreeModelPtr->append();
  treeSel =  findTreeView.get_selection();
  /* assign headers*/
 
findTreeView.append_column("ID",findColumns.colNumber);
 
findTreeView.append_column("foo1",findColumns.foo1ColText);
 
findTreeView.append_column("foo2",findColumns.foo2ColText);
 
findTreeView.append_column("foo3",findColumns.foo3ColText);
 


  /*add the signal handler*/
 
treeSel->signal_changed().connect(SigC::slot(&findPanel::on_selection_changed));

  /*place tree model in scroll window*/
  findScrolledWindow.set_border_width(5);
  findScrolledWindow.add(findTreeView);
  findScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC,
Gtk::POLICY_AUTOMATIC);
  findScrolledWindow.set_size_request(250,200);

  Gtk::TreeModel::Row row = *iter;
  row[findColumns.foo1ColText] = "Billy";
  row[findColumns.foo2ColText] = "Bob";
  row[findColumns.foo3ColText] = "junk";
  iter = findTreeModelPtr->append();
  row = *iter;
  row[findColumns.foo1ColText] = "John";
  row[findColumns.foo2ColText] = "Doe";
  row[findColumns.foo3ColText] = "junk";
  
  add(findScrolledWindow);
  show_all_children();
}

findPanel::~findPanel() {
}

findModelColumns::findModelColumns() {
  add(colNumber);
  add(foo1ColText);
  add(foo2ColText);
  add(foo3ColText);
}

findModelColumns::~findModelColumns() {
}

void 
findPanel::on_selection_changed() {
}
--code ends


--- kickvb touva be wrote:
> Yada Yuk <yadayuk yahoo com> said:
> 
> > In a TreeView/Liststore I want to detect which row
> has
> > been selected (with single click of mouse).
> > 
> > on_row_activated() does it for double clicks. What
> is
> > the signal for single clicks?
> 
> You need to work with
> Gtk::TreeSelection::signal_changed()
> You can catch the TreeSelection with
> Gtk::TreeView::get_selection()
> 
> Regards,
> 
> Christian Van Brussel
> 
> 
> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com



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