在Gtk中,当在TreeView中使用拖放时,如何防止在行之间丢弃?

Mat*_*hew 6 c# gtk drag-and-drop gtk# gtktreeview

我正在测试一个看起来像这样的窗口:

替代文字

将标签拖动到卡片可将标签链接到卡片.将卡片拖动到标签也是如此.

在两张牌之间放一个标签,或者在两张牌之间放一张牌是没有意义的.我可以在Handle...DataReceived函数中忽略这些结果,如下所示:

if (dropPos != TreeViewDropPosition.IntoOrAfter &&
    dropPos != TreeViewDropPosition.IntoOrBefore)
    return;
Run Code Online (Sandbox Code Playgroud)

但是,在拖动时,用户仍会看到要插入的选项:

替代文字

我该如何防止这种情况发生?

Joh*_*gko 3

您需要连接到drag-motion信号并更改默认行为,以便它永远不会指示之前/之后的下降:

def _drag_motion(self, widget, context, x, y, etime):
    drag_info = widget.get_dest_row_at_pos(x, y)
    if not drag_info:
        return False
    path, pos = drag_info
    if pos == gtk.TREE_VIEW_DROP_BEFORE:
        widget.set_drag_dest_row(path, gtk.TREE_VIEW_DROP_INTO_OR_BEFORE)
    elif pos == gtk.TREE_VIEW_DROP_AFTER:
        widget.set_drag_dest_row(path, gtk.TREE_VIEW_DROP_INTO_OR_AFTER)
    context.drag_status(context.suggested_action, etime)
    return True
Run Code Online (Sandbox Code Playgroud)