Re: [gtk2-perl-xs] Setting a cursor on a label



JörnReder said:

Hiho,

I have a problem setting a cursor on a label. I'm trying something like
this:

  my $label = Gtk2::Label->("Test");
  $label->show;

  my $event = Gtk2::EventBox->new;
  $event->show;
  $event->add($label);

  my $cursor = Gtk2::Gdk::Cursor->new ("GDK_HAND2");
  $event->window->set_cursor($cursor);

but $event->window is not defined. I thought I have to call
$event->realize to get the window, but that crashes the program with a
long dump of critical assertions, so I'm obviously doing something
wrong.


the GdkWindow needs a parent!  add the event box to a container before you try
to realize it.


this just worked for me:


 use Gtk2;
 Gtk2->init;

 $w = Gtk2::Window->new;
 $w->set_border_width (16);
 $w->signal_connect (delete_event => sub {exit});

 $l = Gtk2::Label->new ('hi there');
 $e = Gtk2::EventBox->new;

 $e->add ($l);
 $w->add ($e);

 $e->realize;
 $e->set_cursor (Gtk2::Gdk::Cursor->new ('hand2');

 $w->show_all;
 Gtk2->main;

the realize doesn't work unless the widget has a parent, and the cursor won't
show up unless the window was realized before setting the cursor.  (and for
those wondering why you need an EventBox -- labels don't have their own
windows, and you must have a window to set a cursor.)

-- 
muppet <scott at asofyet dot org>



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