Drop between rows of column view

How can I implement drag&drop with target between rows of a column view? Or at least onto the rows?

Actually I failed to find any working example of dnd with column view, have you seen any?

You do this using the relative position of the widget representing the dragged element in relation to the rows. I usually do it like this:

If the widget is in the bottom 30% of a row when dropped, it’s added below it. If it’s in the top 30%, it’s added above it. If it’s in the remaining 40%, the behavior depends on your desires. In my case, I swap the dragged row with the target row.

You mean I should put DropTarget on whole ColumnView and then use Widget::pick() to somehow check which row is the closest?

If so, is there any easy way to telegraph to user the result of the action? Like to draw a horizontal line in place where rows will be inserted?

Nah, I still don’t see how it can be done. With pick() I can get a widget closest to the cursor, but how can I map the widget to its index in the list store? Especially when the widget is some internal “GtkColumnViewCellWidget”

Sorry, maybe I wasn’t very clear. When you’re creating your row using a row-factory, you should add a Gtk.DropControllerMotion, a Gtk.DragSource, and a Gtk.DropTarget to the row. The DropControllerMotion will allow you to track the position of the widget representing the dragged object relative to the row.

If you add the Gtk.DropTarget directly to the Gtk.ColumnView, it will be more difficult to determine the exact location for the dragged object. Once added to the row, you can use the row’s data, including the position of the row’s data object in the Gtk.ListStore, to determine exactly where the dragged object should be inserted.

@kriptolix
Hmm. I may have done something wrong, but I’ve already tried to use row factory and failed: it seems the row factory uses ColumnViewRow, which is not a widget and therefore it cannot bind to any controller. It seems to be meant only to set some config before creation.

I’m unable to find any way to access the row widget. ColumnViewRowWidget is not even part of public API. Even uncouth calling .parent() on widget added to cell will ultimately lead to some assertion errors.

Unfortunately, I don’t have any working examples. It seems that the row-factory was previously implicit, and starting with 4.12, that changed. I’m not sure how the row-factory interacts with the column-factory, or if I need to choose one or the other. My comment was based on how Gtk.ListView works, where only the row-factory exists.

I’ll look for an example, if I find one I’ll link it here.

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