RE: button_press_event from image



Why does the Gtk2::Image not inherit the signals from Gtk2::Widget -
amongst them button_press_event?

no widget listens to all the events by default (the more they are, the
more traffic they cause on the X-GDK-GTK line): events must
specifically be added using Gtk2::Widget::add_events() or
Gtk2::Widget::set_events().  the only widget that enables all the
events by default is Gtk2::EventBox

you may subclass Gtk2::Image and use Gtk2::Widget::add_events() inside
your constructor, so that you can avoid the extra packing:

package My::ActiveImage

use Gtk2;
use Glib::Object::Subclass
       'Gtk2::Image';
sub INIT_INSTANCE {
  my ($self) = @_;
  $self->add_events([ qw( button-press-mask button-release-mask ) ]);
}

1;

and then you can use My::ActiveImage and connect to the button-press-
event.

I learn something every day on this list. Thanks!

Jeff



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