Change Mouse Cursor



Hi All,

Was wondering if I could get some help.  I am currently trying to
change the mouse cursor to a hand on a 'button_press_event'.  I was
hoping to change it to a hand for future grabbing and dragging of a
canvas but can't even get the cursor to change so the dragging
question will have to wait.

Please find attached the simple glade file I am using that contains a
scrolled window and a viewport into which I'm putting a canvas which
at this stage is unused.

Below is the code I am using:
#!/usr/bin/perl
package main;

use strict;

use Glib qw/TRUE FALSE/;
use Goo::Canvas;
use Gtk2 -init;

# Read in glade file with gui
our $builder = Gtk2::Builder->new;
$builder->add_from_file("GooTest.glade");

# Get main window from widget tree.
my $main_window = $builder->get_object('window1') || die "Can't find window.\n";
my $scrwin = $builder->get_object('scrolledwindow1') || die "Can't
find scrolled window.\n";
my $canvas = Goo::Canvas->new();
$scrwin->add_with_viewport($canvas);
$canvas->show;

&connect_signals;

# Quit when user clicks on the close button/alt-f4 etc.
$main_window->signal_connect (destroy => sub { Gtk2->main_quit; });

# Maximise window
#$main_window->maximize;

# Run main loop.
Gtk2->main;


sub connect_signals
{
    # Respond to mouse button presses
    $scrwin->signal_connect(button_press_event => \&button_press_event);
    $scrwin->signal_connect(button_press_event => \&change_cursor);

}

sub button_press_event
{
  my ($widget, $event) = @_;

  if ($event->button == 1)
  {
    print join ' ', $event->coords,"\n";
  }

  return TRUE;
}

sub change_cursor
{

    my ($widget, $event) = @_;
    my $cursor = Gtk2::Gdk::Cursor->new ('hand1');

    if ($event->button == 1)
    {
        $widget->window->set_cursor($cursor);
    }

    return TRUE;
}

Thanks for any suggestions.

Attachment: GooTest.glade
Description: Binary data



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