Re: [gtkmm] Keyboard/Mouse signals on a TreeView?

Markus Gerwinski wrote:

Murray Cumming Comneon com wrote:
It absolutely should react on some key, for accessibility reasons. You might
play with the demo to see what key it is, but I think it should be enter.

It was SPACE. Well, that's something I can live with.

However, I need the TreeView to react on some other keys, too, and if possible
on a right-button mouse click (for a context menu). Is there a way to get this?
As I said, signal_key_press_event and signal_button_press_event don't seem to
work here.
Well, may be this quote from mail-list archive will help you:
Here is an example of why I need to get a Gtk::CellRenderer for a
specific cell:
I have a TreeView with 2 columns. When the user clicks in a cell with
mousebutton1 I want to set the background color of the cell he clicked
in to red;
class ModelColumns : public Gtk::TreeModel::ColumnRecord
ModelColumns()  {   add(m_col_a); add(m_col_b);   add(m_col_visible);  }
Gtk::TreeModelColumn<string> m_col_a;
Gtk::TreeModelColumn<double> m_col_b;
Gtk::TreeModelColumn<bool> m_col_visible;   };

ModelColumns m_Columns;
Gtk::TreeView m_TreeView;
Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;
m_refTreeModel = Gtk::TreeStore::create(m_Columns);

// Append the columns
m_TreeView.append_column("A", m_Columns.m_col_a);
m_TreeView.append_column("B", m_Columns.m_col_b);

// I register to receive a callback for button press events in the
m_TreeView.signal_button_press_event().connect(  SigC::slot(*this,
&ExampleWindow::on_m_TreeView_button_press), false );

bool  ExampleWindow::on_m_TreeView_button_press(GdkEventButton
Gtk::TreeModel::Path  path;
Gtk::TreeViewColumn*  column;
int cell_x;
int cell_y;
Gtk::TreeModel::Row row;

// catch mouse button1 clicks
switch (eventbutton->type)
    if ( eventbutton->button == 1)
if (m_TreeView.get_path_at_pos(eventbutton->x, eventbutton->y, path, column, cell_x, cell_y )) { // Get the row number int row_num = *path.get_indices().begin(); row = *( m_refTreeModel->children[row_num - 1]);
           // Get the column number
           int column_number = -1;
           while (column != treeView->get_column(column_number))

         // So at this point I have a Gtk::TreeViewColumn, a column
number, a Gtk::TreeModel::Row and a row number
         // I want to get at the CellRendererText * for that cell so I
can do something like this :

         Gtk::CellRendererText* pRenderer =  (I don't know how to do
this .......but it should point to the cellrenderer for the cell the
user clicked in)
         Gdk::Color col("red");
 return false;

Thanks !

This very example from Liza helped me to handle all three mouse buttons.
   Hope it would be helpfull for you, too.
       Igor Gorbounov

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