[Moved] Drop Event on QTextBrowser ? (PyQt)
Hi Guys,
First, I hope I didn’t miss any thread already answering this question.
My problem is fairly simple. I can’t get a drop event to work correctly for a QTextBrowser. It work just fine with a QLineEdit.
Please check code below (and replace QTextBrowser by QLineEdit to see what I expect)
#!/usr/bin/env python
- import os
- import sys
- import tempfile
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- #QLineEdit (to replace below)
- def dragEnterEvent(self, e):
- e.accept()
- print "Dragged"
- def dropEvent(self, e):
- print "Dropped" # This is never printed when using QTextBrowser
- print e.mimeData().text()
- def __init__(self, *args):
- view1 = MyWebView()
- layout.addWidget(view1)
- view1.setAcceptDrops(True)
- layout.addWidget(view2)
- view2.setAcceptDrops(True)
- def dragReceived(self, e):
- e.accept()
- print "Connect Dragged"
- def dropReceived(self, e):
- print "Connect Dropped"
- def main():
- w = MyWindow()
- w.show()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
Thanks for your help
Aurelien
4 replies
It’s basically a QTextEdit. Maybe the QTextEdit drag ‘n’ drop [doc.trolltech.com] documentation helps.
Thanks for your help.
I managed to find my problem. I actually need to accept dragMoveEvent which is the type of Drag action that emit a TextBrowser when you drag and drop a file from your desktop onto your QTextBrowser.
For information (action 2)
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qt.html#DropAction-enum
Just by adding the following code it work well.
- def dragMoveEvent(self, inEvent):
- """
- Need to accept DragMove to catch drop for TextBrowser
- """
- inEvent.accept()
Thanks all
You must log in to post a reply. Not a member yet? Register here!
