Prevent loss of selection Treeview when dragging

I have a setting gtk.Treeviewas a drag source:

self.drag_source_set(gtk.gdk.BUTTON1_MASK, targets, gtk.gdk.ACTION_COPY)

a TreeSelection- SELECT_MULTIPLE.

But every time I try to drag a few lines, the cursor will move to the current position of the mouse, resetting the selection to the current line. Although the mouse is above one of the selected lines. It only works when I hold the Shiftor button Ctrl.

What's happening?

Change 1:

I installed tree-tree tree to rule out any errors in my code, and it does the same.

Edit 2:

I found a piece of code that does what I want. This is from libd quod sources called MultiDragTreeView.

+3
2

, , . quod libet, 'MultiDragTreeView'. :

"""TreeView with multirow drag support:
* Selections don't change until button-release-event...
* Unless they're a Shift/Ctrl modification, then they happen immediately
* Drag icons include 3 rows/2 plus a "and more" count"""
+1

, , .

def on_iconview_button_press_event(widget, event):
    if event.type != Gdk.EventType.BUTTON_PRESS or event.button != 1:
        return
    if (event.state & Gdk.ModifierType.CONTROL_MASK):#do no changes if ctrl is pressed
        return
    path = widget.get_path_at_pos(event.x, event.y)
    if not path:
        return
    if widget.path_is_selected(path):
        widget.unselect_path(path)
        event.state |= Gdk.ModifierType.CONTROL_MASK
        return
iconview.connect('button-press-event', on_iconview_button_press_event)
0

Source: https://habr.com/ru/post/1772074/


All Articles