[Qgis-developer] Using the QgsBrowserModel in Python

Hugo Mercier hugo.mercier at oslandia.com
Thu Jul 30 04:47:11 PDT 2015


Hi,

On 29/07/2015 17:50, Ludovic Delauné wrote:
> Hi devs,
> 
> i'm trying to use the QgsBrowserModel in a Python plugin.
> I need to get the URI from a selected Item in the QTreeView, i expected to have a QgsLayerItem returned by the dataItem() in order to get the uri() member but a QgsDataItem
> is returned instead.
> Given a QgsDataItem, is it possible to get the uri of my data source ?
> 
> Is this a bug due to the binding (https://github.com/qgis/QGIS/blob/feb3bee85837d707b1b10c14064fcb55364e282d/python/core/qgsbrowsermodel.sip) or i'm not in the right way ?
> 
> Here are the few steps to reproduce the problem in a console:
> 
> -------
> from PyQt4.QtGui import QTreeView
> tv = QTreeView(None)
> m = QgsBrowserModel()
> tv.setModel(m)
> tv.show()
> m.dataItem(tv.currentIndex())
> --------
> output is :
> <qgis._core.QgsDataItem object at 0x7f6cb8bcca68>

Apparently, this is because QgsDataItem has nothing to convert to its
derived types in the Python bindings. I'll add a %ConvertToSubClassCode.

Thanks for the report



More information about the Qgis-developer mailing list