开发者

How do I handle button presses in Gtk2::Image objects?

I've been trying to get an Gtk2::Image object in this Perl Gtk2 application to get to react to button presses, but to no avail. The image shows as expected but the button events don't get handled. What am I missing?

  my $img = Gtk2::Image->new_from_file( $file );
  $img->set_property( sensitive => 1 );
  $img->can_focus( 1 );
  $img->set_events([qw/ button-press-mask button-release-mask /]);
  $img->signal_connect(
    'button-press-event' => sub {
      my ( $self, $event ) = @_;
      print STDERR "Coords: ", $event->get_coords;
      return;
    });
  $wi开发者_如何学运维ndow->add( $img );
  $window->show_all;


GtkImage does not have any window associated to it; in other words it does not react to any X event (generally, the ones ending with -event).

The common way to handle events on those widgets is by using GtkEventBox, that is placing the GtkImage widget inside a GtkEventBox and connecting X event signals to this GtkEventBox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜