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

JörnReder said:


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

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

  my $event = Gtk2::EventBox->new;

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

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

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;

 $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->set_cursor (Gtk2::Gdk::Cursor->new ('hand2');


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]