Drag and Drop an item in QT

94 views
Skip to first unread message

Rishis3D

unread,
Jun 26, 2014, 5:51:30 AM6/26/14
to python_in...@googlegroups.com
Hi Guys..

how to drag and drop and item from one widget to another widget.. eg i have multiple qlistwidget.. i want to drag an item from one qlistwidget to another qlistwidget.. 

thanks,
rishis3d

Justin Israel

unread,
Jun 26, 2014, 7:47:15 AM6/26/14
to python_in...@googlegroups.com
QListWidget has a lot of the drag and drop functionality already defined, so it is just a few features that have to be enabled:
class DragDrop(QtGui.QWidget):

    def __init__(self):
        super(DragDrop, self).__init__()

        self.list1 = QtGui.QListWidget()
        self.list1.setDragEnabled(True)
        self.list1.setDropIndicatorShown(True)
        self.list1.setDragDropMode(self.list1.DragDrop)
        self.list1.setDefaultDropAction(QtCore.Qt.MoveAction)

        self.list2 = QtGui.QListWidget()
        self.list2.setDragEnabled(True)
        self.list2.setDropIndicatorShown(True)
        self.list2.setDragDropMode(self.list1.DragDrop)
        self.list2.setDefaultDropAction(QtCore.Qt.MoveAction)

        self.list1.addItems(["Item%02d" % i for i in xrange(5)])

        layout = QtGui.QHBoxLayout(self)
        layout.addWidget(self.list1)
        layout.addWidget(self.list2)




--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f39d0041-fb02-41ce-8978-94b8e2b6e3c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rishis3D

unread,
Jun 29, 2014, 1:36:46 PM6/29/14
to python_in...@googlegroups.com
thanks justin.. its working.. 

is there any way to emit a signal, when i drop and item to a list-widget? so tat i can use that signal for another function call

thanks..
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Jun 29, 2014, 3:20:50 PM6/29/14
to python_in...@googlegroups.com

If you redefine the dropEvent() method on the QListWidget then you will be able to emit a signal

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e917c470-64e6-4457-8ffc-28b03f790f75%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages