[PyQt] Drop to system
Baz Walter
bazwal at ftml.net
Thu Sep 9 18:01:44 BST 2010
On 09/09/10 14:29, Massimo Di Stefano wrote:
> tring to learn how to use the Drag class, i tried to hack the "draggabletext.py" from the pyqt source :
>
> - http://www.geofemengineering.it/draggabletext_.py
>
> i'm now blocked on how to reuse the same code
> to drag a QTableWidgetItem from a QtTablewidjet,
> the code i'm starting from is :
>
> - http://www.geofemengineering.it/table_ui.py
>
> - http://www.geofemengineering.it/table.py
>
> i'm tring to learn how to use the class " bool QTableWidget::dropMimeData " have you any hints ?
i don't know what program you're using to view kml files, but the
following works for me if i drop the url onto google-earth:
import sys, os
from PyQt4.QtCore import Qt, SIGNAL, QMimeData, QUrl
from PyQt4.QtGui import (
QApplication, QTableWidget, QTableWidgetItem, QDrag,
)
class Window(QTableWidget):
def __init__(self):
QTableWidget.__init__(self, 1, 1)
self.setEditTriggers(QTableWidget.NoEditTriggers)
self.connect(self, SIGNAL('itemPressed(QTableWidgetItem*)'),
self.handleItemPressed)
kmlfile = os.path.join(os.getcwd(), 'test.kml')
self.setItem(0, 0, QTableWidgetItem(kmlfile))
def handleItemPressed(self, item):
if app.mouseButtons() == Qt.LeftButton:
drag = QDrag(self)
data = QMimeData()
data.setUrls([QUrl.fromLocalFile(item.text())])
drag.setMimeData(data)
drag.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec_())
More information about the PyQt
mailing list