[Qgis-developer] Using the QgsBrowserModel in Python

Ludovic Delauné ludovic.delaune at oslandia.com
Wed Jul 29 08:50:12 PDT 2015


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>


QGIS version used : 2.8.2

regards.

-- 
Ludovic


More information about the Qgis-developer mailing list