[QGIS-Developer] Handling QStandardItem drop onto QGIS map canvas

maryla GIS maryla4gis at gmail.com
Tue Mar 25 03:08:53 PDT 2025


Hi all,

I’m writing a QGIS plugin which is kind of a 'wrapper' over layers in the
database. Inside the plugin's dock widget, I have a QTreeView. Inside this
tree, I’ve added QStandardItems. The plugin itself and these items hold
information that allows creating a vector layer from the database using
QgsDataSourceUri(). The layer is added after clicking a push button, but I
want to be able to add a layer by dragging and dropping a QStandardItem
onto the map canvas.

Now it looks like this: I can drag and drop an item, but when it hovers
over the map canvas, a red icon appears, and dropping the item there does
nothing.

[image: draganddroperror.png]

How should I handle this action?
Do I need to write custom drag-and-drop handlers for QStandardItem? How to
recognize from an item point of view that it's dropped onto a map canvas?
Or should I use classes like QgsCustomDropHandler or QgsMimeDataUtils? How
to recognize from a map canvas point of view that QStandardItem is being
dropped?

To be honest, I have no idea how to implement any of these solutions and
how to start solving this problem. The mix of QStandardItem and QGIS
classes confuses me. Can anyone give me some advice?


Regards,
Maryla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250325/57563007/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: draganddroperror.png
Type: image/png
Size: 6834 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250325/57563007/attachment.png>


More information about the QGIS-Developer mailing list