PDA

View Full Version : Drag and drop problem with Qt 4.8.6, Pyside 1.2.2 and Python 2.7



Lovehina13
2nd October 2014, 11:29
Hello,

I have a QWidget that contains a QListWidget and a QTextEdit (each reimplemented).
I want to have the following feature and behaviour :
- when an item from the QListWidget is selected then dragged and dropped to the QTextEdit, the item is inserted at the cursor position.
- when a text from the QTextEdit is selected then dragged and dropped to the same QTextEdit, the text is moved at the cursor position.

For each drag/dropEvent, I have the main code (dragEnterEvent example) :
def dragEnterEvent(self, event):
print "MyQTextEdit.dragEnterEvent()", event
if isinstance(event.source(), QListWidget) :
# Specific code when QListWidget
...
event.accept()
else :
# Standard behaviour
super(MyQTextEdit, self).dragEnterEvent(event)

Unfortunately, when I call from Python and PySide the "event.source()" method, it provokes a SEGFAULT when I reuse the event object.
I did the same program in pure C++/Qt and it works fine.

Moreover, the following code works :
def dragEnterEvent(self, event):
print "MyQTextEdit.dragEnterEvent()", event
super(MyQTextEdit, self).dragEnterEvent(event)
But the following code crashes (notes the "event.source()" in print) :
def dragEnterEvent(self, event):
print "MyQTextEdit.dragEnterEvent()", event, event.source()
super(MyQTextEdit, self).dragEnterEvent(event)

I suppose there is a problem in Python or PySide library when using the "event.source()" function which returns a pointer from a volatile QWidget which seems persistent after in Python and which doesn't exist anymore when I reuse the event object in Qt.

Thanks for your help.

The code is in attachment.

Added after 43 minutes:

The C++ corresponding code that works fine in attachment.

Lovehina13
2nd October 2014, 13:15
The Python code works if we use PyQt4 instead of PySide.
I think I'll report this problem to the Qt development team.