Domanda

I want to convert my pixbuf to "GtkSelectionData" so, how can I convert it in c++ ? Below is my sample code.

clipboard   =   gtk_clipboard_get_for_display (gdk_display_get_default (),
                                                     GDK_SELECTION_CLIPBOARD);
                GdkPixbuf *pixbuf;
                pixbuf = gtk_clipboard_wait_for_image ( clipboard );

                if ( pixbuf != NULL )
                {
                    int width, height;
                    width  = gdk_pixbuf_get_width (pixbuf);
                    height = gdk_pixbuf_get_height (pixbuf);
                    //printf("width : %d", width);
                    GtkSelectionData *selectionData;
                gtk_selection_data_set_pixbuf(selectionData,pixbuf);
                g_object_unref (pixbuf);

                 }

Error: cannot convert ‘GdkPixbuf* {aka _GdkPixbuf*}’ to ‘GtkSelectionData* {aka _GtkSelectionData*}’ in initialization

Thanks, Jimit

È stato utile?

Soluzione

If you look at the documentation, you'll see that there's a function

gtk_selection_data_set_pixbuf(GtkSelectionData*, GdkPixbuf*)

which does exactly what you want.

The question then is, where do you get the GtkSelectionData from? The answer is that usually, when a drop happens (or middle-click is pressed), GTK runs a callback giving you the selection data pointer and asking you to fill it in with the actual bytes that should be transferred.

But the whole drag and drop/clipboard stuff is horribly complicated in GTK. There are a couple of tutorials on the Gnome wiki which help though, I'd suggest having a read of them :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top