Jquery sortable drag and drop not showing 'move' cursor
By : user3718859
Date : March 29 2020, 07:55 AM
I hope this helps . The problem seems to be, that your CSS setting is used across all states. You can get around this by setting the cursor for "dragging" as well via CSS: code :
#contentLeft li:hover {
cursor: pointer;
}
#contentLeft li.ui-sortable-helper{
cursor: move;
}
|
how to drag and drop a div into another div and after dragging the div do not move using jQuery
By : Zahid
Date : March 29 2020, 07:55 AM
it fixes the issue If by do not move, you mean, don't move the original item, then with a combination of dragable with revert set to true, and dropable http://jqueryui.com/droppable/#revert code :
$(function() {
$( "#draggable" ).draggable({ revert: "valid" });
$( "#droppable" ).droppable();
});
|
Move element to position after Jquery Drag & Drop
By : user5237585
Date : March 29 2020, 07:55 AM
it fixes the issue All your Javascript code is working but the problem here is that your divs are positioned static, meaning that 'top' and 'left' properties won't work on them. A good fix is to position them absolute at the moment of dropping so they will move to the given values.
|
How can copy with drag and drop from one list but use move for internal drag and drop
By : tjyan
Date : November 03 2020, 11:01 PM
it fixes the issue Well this is what I came up with. I'm setting a class data variable when the item is clicked so I can tell where it came from when the the item is dropped. I tried using a class variable inside DragDropListWidget but for some reason it would only store the local name of the current list.. weird. A global variable also worked but is not desirable. code :
import sys
from PyQt4 import QtGui , QtCore
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
layout=QtGui.QHBoxLayout(w)
dragList=DragDropListWidget()
layout.addWidget(dragList)
d=data()
dragList.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
dragList.name='dragList'
dragList.populate(['one','two','three'])
dragList.data=d
dragList2=DragDropListWidget()
dragList2.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
dragList2.name='dragList2'
dragList2.external='dragList2'
dragList2.data=d
layout.addWidget(dragList2)
w.show()
sys.exit(app.exec_())
class data(object):
def __init__(self, parent=None):
self.origin='new'
class scriptsWidget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self)
self.name=''
self.widget_QHBoxLayout = QtGui.QHBoxLayout(self)
self.widget_QHBoxLayout.setSpacing(0)
self.widget_QHBoxLayout.setContentsMargins(0, 0, 0, 0)
self.name_QLabel = QtGui.QLabel(self)
self.widget_QHBoxLayout.addWidget(self.name_QLabel)
self.user_QLabel = QtGui.QLabel(self)
self.widget_QHBoxLayout.addWidget(self.user_QLabel)
self.widget_QHBoxLayout.setSpacing(0)
self.widget_QHBoxLayout.setContentsMargins(0, 0, 0, 0)
def setName(self,name):
self.name_QLabel.setText(name)
self.name=name
def setUser(self,user):
self.user_QLabel.setText(user)
class customQListWidgetItem(QtGui.QListWidgetItem):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self)
self.name=''
self.list=''
def setName(self,name):
self.name=name
class DragDropListWidget(QtGui.QListWidget):
def __init__(self, parent = None):
super(DragDropListWidget, self).__init__(parent)
self._dropping = False
self.itemPressed.connect(self.clicked)
self.data=''
self.name=''
self.external=''
self.internal=False
def clicked(self):
global origin
self.data.origin=self.name
def dragMoveEvent(self, event):
if event.mimeData().hasUrls():
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
super(DragDropListWidget, self).dragMoveEvent(event)
def dropEvent(self, event):
if event.mimeData().hasText():
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
self.emit(QtCore.SIGNAL("dropped"), links)
else:
if self.external is self.name and self.data.origin is not self.name:
print('external')
event.setDropAction(QtCore.Qt.CopyAction)
items = []
for index in xrange(self.count()):
items.append(self.item(index))
print items
super(DragDropListWidget, self).dropEvent(event)
for index in xrange(self.count()):
if self.item(index) not in items:
print(index)
self.populateDrop(self.item(index), index, [self.item(index).data(QtCore.Qt.UserRole).toPyObject()])
else:
print('internal')
event.setDropAction(QtCore.Qt.MoveAction)
super(DragDropListWidget, self).dropEvent(event)
self.data.origin = None
def populateDrop(self,item,row,items=[]):
for i in items:
widget = scriptsWidget()
widget.setName(i)
widget.setUser('x')
self.takeItem(row)
item = customQListWidgetItem()
item.setName(i)
item.setWhatsThis(i)
item.list=self.name
data = (i)
item.setData(QtCore.Qt.UserRole, data)
self.insertItem (row, item)
self.setItemWidget(item,widget)
def populate(self,items=[]):
self.clear()
for i in items:
print(i)
widget = scriptsWidget()
widget.setName(i)
widget.setUser('x')
item = customQListWidgetItem()
item.setName(i)
item.list=self.name
data = (i)
item.setData(QtCore.Qt.UserRole, data)
self.addItem(item)
self.setItemWidget(item,widget)
if __name__ == '__main__':
main()
|
How to move only particular item using drag and drop JQuery?
By : vikash shrivastava
Date : March 29 2020, 07:55 AM
it helps some times This is best done using update or receive callbacks. The key is: ui.sender.sortable("cancel"); This will revert the change. Working Example: https://jsfiddle.net/Twisty/4f5yh3pa/ code :
<ul id="sortable1" class="connectedSortable">
<li class="ui-state-default acceptable">StoreID</li>
<li class="ui-state-default">ItemLookupCode</li>
<li class="ui-state-default">ExtendedCost</li>
<li class="ui-state-default">Quantity</li>
<li class="ui-state-default">Price</li>
</ul>
<ul id="sortable2" class="connectedSortable">
</ul>
.connectedSortable {
border: 1px solid #eee;
width: 142px;
min-height: 20px;
list-style-type: none;
margin: 0;
padding: 5px 0 0 0;
float: left;
margin-right: 10px;
}
#sortable1 {
background: #fff;
}
#sortable2 {
background: #999;
}
.connectedSortable li {
margin: 0 5px 5px 5px;
padding: 5px;
font-size: 1.2em;
width: 120px;
}
$(function() {
$(".connectedSortable").sortable({
connectWith: ".connectedSortable",
update: function(e, ui) {
if ($(e.target).attr("id") == "sortable2") {
if (ui.item.hasClass("acceptable")) {
console.log($(this).attr("id") + " accepted item: ", ui.item);
} else {
console.log($(this).attr("id") + " rejected item: ", ui.item);
ui.sender.sortable("cancel");
}
}
}
}).disableSelection();
});
|