GTK3 : How to drag and drop GTKLabel

Hi,

I’m working on GTK3 application in cpp. I’m trying to implement Drag and Drop for GTKLabel. I tried drag and drop for GTKEntry and GTKButton, for these i was able to get “Drag-Begin”, “Drag-motion” and “Drag-Drop” events,but im not able to get these events for GTKLabel

GtkTargetEntry  gten[1] = { g_strdup("dummy"), GTK_TARGET_SAME_APP, (guint)pID };

gtk_drag_source_set(widget, GDK_BUTTON1_MASK, gten, 1, GDK_ACTION_COPY);gtk_drag_dest_set(widget, GTK_DEST_DEFAULT_ALL, gten, 1, GDK_ACTION_COPY);
g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(ButtonClickHandler), nullptr);
g_signal_connect(G_OBJECT(widget), "drag-begin", G_CALLBACK(ButtonDragBeginHandler), nullptr);
g_signal_connect(G_OBJECT(widget), "drag-drop", G_CALLBACK(ButtonDragDropHandler), nullptr);
g_signal_connect(G_OBJECT(widget), "drag-motion", G_CALLBACK(ButtonDragMotionHandler), nullptr);

Same set of code worked for GTKEntry and GTKButton, but it did not work for GTKLabel.

How to fix this issue?

Thank you,
Harshithraj P

GtkLabel has no backing window, so it cannot support drag and drop.

You want to add the label into a GtkEventBox, and then have the event box be the responsible for the drag and drop operations.

Also:

You’re leaking the string, here.

1 Like

Thank You, this was helpful

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.