GdkPixbuf and click events

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GdkPixbuf and click events

Gtk+ - Apps Dev mailing list
I have a program that adds a GdkPixbuf to a GtkTextView. I would like to right click on the image and capture the mouse click event and execute a callback function. Is there any way of achieving this using GdkPixbuf?

Thanks,
Ferdinand
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GdkPixbuf and click events

Chris Moller-3
I'm not sure it will work, but have you tried wrapping the pixbuf in a
GtkEventBox?


On 08/02/17 18:02, Ferdinand Ramirez via gtk-app-devel-list wrote:

> I have a program that adds a GdkPixbuf to a GtkTextView. I would like to right click on the image and capture the mouse click event and execute a callback function. Is there any way of achieving this using GdkPixbuf?
>
> Thanks,
> Ferdinand
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
>

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GdkPixbuf and click events

infirit
In reply to this post by Gtk+ - Apps Dev mailing list
Op 08/03/2017 om 12:02 AM schreef Ferdinand Ramirez via gtk-app-devel-list:
> I have a program that adds a GdkPixbuf to a GtkTextView. I would like to right click on the image and capture the mouse click event and execute a callback function. Is there any way of achieving this using GdkPixbuf?

Not directly with a pixbuf but this is what a GtkDrawArea [1] is for.
Create a new drawing area and add the event mask you are interested in
(GDK_BUTTON_PRESS_MASK for example) with gtk_widget_add_events. Finally
connect to the signal corresponding to the event (following earlier
example button-press-event) and do what you want in a callback function.

Note that you have to handle drawing yourself which the docs provide an
example of.

~infirit

[1] https://developer.gnome.org/gtk3/stable/GtkDrawingArea.html

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GdkPixbuf and click events

Gtk+ - Apps Dev mailing list
In reply to this post by Gtk+ - Apps Dev mailing list

Hi Ferdinand,

You can also try putting the pixbuf in an image widget and that into an event box.

Eric


//gcc -Wall right_click1.c -o right_click1 `pkg-config --cflags --libs gtk+-3.0`

#include<gtk/gtk.h>

static GdkPixbuf* draw_a_pixbuf()
  {
    cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 20, 20);
    cairo_t *cr=cairo_create(surface);
   
    cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
    cairo_paint(cr);

    GdkPixbuf *pixbuf=gdk_pixbuf_get_from_surface(surface, 0, 0, 20, 20);

    cairo_destroy(cr);
    cairo_surface_destroy(surface);
    return pixbuf;
  }
static gboolean start_press(GtkWidget *widget, GdkEvent *event, gpointer data)
  {
    if(event->button.button==3) g_print("Right Click\n");
    return TRUE;
  }
int main(int argc, char *argv[])
  {
    gtk_init (&argc, &argv);

    GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Right Click");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GdkPixbuf *pixbuf=draw_a_pixbuf();

    GtkWidget *image=gtk_image_new_from_pixbuf(pixbuf);

    GtkWidget *event=gtk_event_box_new();
    g_signal_connect(event, "button-press-event", G_CALLBACK(start_press), NULL);
    gtk_container_add(GTK_CONTAINER(event), image);
   
    GtkWidget *textview=gtk_text_view_new();
    gtk_text_view_add_child_in_window(GTK_TEXT_VIEW(textview), event, GTK_TEXT_WINDOW_TEXT, 40, 40);
    gtk_widget_set_hexpand(textview, TRUE);
    gtk_widget_set_vexpand(textview, TRUE);
   
    GtkWidget *grid=gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), textview, 0, 0, 1, 1);      
   
    gtk_container_add(GTK_CONTAINER(window), grid);

    gtk_widget_show_all(window);

    gtk_main();

    g_object_unref(pixbuf);

    return 0;
  }

 

 

 

-----Original Message-----
From: Ferdinand Ramirez via gtk-app-devel-list <[hidden email]>
To: gtk-app-devel-list <[hidden email]>
Sent: Thu, Aug 3, 2017 8:13 am
Subject: GdkPixbuf and click events

I have a program that adds a GdkPixbuf to a GtkTextView. I would like to right click on the image and capture the mouse click event and execute a callback function. Is there any way of achieving this using GdkPixbuf?

Thanks,
Ferdinand
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Loading...