Re: [gtkmm] Q: How to get button_press_event for Gtk::TreeView



Thanks to everyone for your support.

Daniel, you were right: the only thing I was missing was
the optional second argument to connect.

Now everything works as expected.


Summary:

--8<-------------------------------------------------
class CustomView : public Gtk::TreeView
{
   bool sig_button_pressed(GdkEventButton *ev);
};

bool CustomView::sig_button_pressed(GdkEventButton *ev)
{
   if (ev->type == GDK_BUTTON_PRESS && ev->button == 3) {
      std::cout << "Button 3 pressed" << std::endl;
	// pop up a menu here ...
      // and stop handling this event
      return true;
   } else {
      // ignored, have processing done by default handler
     return false;
   }
}
--8<-------------------------------------------------

and connect like this:

--8<-------------------------------------------------
CustomView m_tree_view;

m_tree_view.signal_button_press_event( ).connect(
       SigC::slot( *this, &CustomView::sig_button_pressed ), false ); 

--8<-------------------------------------------------


Thanks again,

Joachim Kuth.

> -----Original Message-----
> From: "Garriss, Michael" <Michael Garriss abacus-direct com>
> To: 'Daniel Elstner' <daniel elstner gmx net>,
> 	Joachim Kuth T_SYSTEM sysde eads net
> Cc: Jarek Dukat <madmaxer poczta fm>, gtkmm-list gnome org
> Subject: RE: [gtkmm] Q: How to get button_press_event for 
> Gtk::TreeView
> Date: Fri, 8 Nov 2002 12:18:43 -0700 
> 
> I was forced to connect button release:
> 
> m_tree_view.signal_button_release_event( ).connect(
>       SigC::slot( *this, &view::sig_button_released ) ); 
> 
> > -----Original Message-----
> > From: Daniel Elstner [mailto:daniel elstner gmx net]
> > Sent: Friday, November 08, 2002 12:22 PM
> > To: Joachim Kuth T_SYSTEM sysde eads net
> > Cc: Jarek Dukat; gtkmm-list gnome org
> > Subject: Re: [gtkmm] Q: How to get button_press_event for 
> > Gtk::TreeView
> > 
> > 
> > Am Fre, 2002-11-08 um 18.09 schrieb Jarek Dukat:
> > > 
> > > If you want to receive button_press events you must enable 
> > them first.
> > > 
> > > > - Is there a way to disable the default behaviour that
> > > >   pressing *any* mouse button will change the selection?
> > > >   E.g. I want to change the selection with button1, 
> > > >   show a popup menu with button3, etc.
> > > 
> > > I'd like to know it too.
> > 
> > If you can't override on_button_press_event() then pass 
> > 'false' for the
> > second argument of signal_button_press_event().connect().  The default
> > is 'true' which means "connect after".
> > 
> > I hope this is what you meant and it actually helps (I haven't tried).
> > 
> > --Daniel



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