Bug report #17152

Problem with type of (python) QgsComposerItem?

Added by Loïc BARTOLETTI about 3 years ago. Updated almost 3 years ago.

Status:Closed
Priority:Normal
Assignee:Denis Rouzaud
Category:Python bindings / sipify
Affected QGIS version:2.14.18 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:up/downstream
Crashes QGIS or corrupts data:No Copied to github as #:25051

Description

I have a bug on Debian and FreeBSD exactly like this We're bringing out this bug #3236

I want to play with some items of a composition. The example below is to play with a table with the id: "attr" of the second composition
I tested it on different versions of QGis and different systems:

QGis 3 Debian

myComposition = QgsProject.instance().layoutManager().compositions()[1]
table = myComposition.getComposerItemById('attr')
type(table)
<class 'qgis._core.QgsComposerItem'>
table.columns()
Traceback (most recent call last):
File "/usr/lib/python3.5/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
AttributeError: 'QgsComposerItem' object has no attribute 'columns'
table.type()
65651

QGis 3 Windows

myComposition = QgsProject.instance().layoutManager().compositions()[1]
table = myComposition.getComposerItemById('attr')
type(table)
<class 'qgis._core.QgsComposerItem'>
table.type()
65651
table.multiFrame()
Traceback (most recent call last):
File "C:\OSGEO4~1\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
AttributeError: 'QgsComposerItem' object has no attribute 'multiFrame'
table.columns()
Traceback (most recent call last):
File "C:\OSGEO4~1\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
AttributeError: 'QgsComposerItem' object has no attribute 'columns'

QGis 2.14 Debian

myComposition = iface.activeComposers()[1].composition()
table = myComposition.getComposerItemById('attr')
type(table)
<class 'qgis._core.QgsComposerItem'>
table.columns()
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'QgsComposerItem' object has no attribute 'columns'
table.type()
65649
table.multiFrame()
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'QgsComposerItem' object has no attribute 'multiFrame'

QGis 2.18 FreeBSD

myComposition = iface.activeComposers()[1].composition()
table = myComposition.getComposerItemById('attr')
type(table)
<class 'qgis._core.QgsComposerItem'>
table.columns()
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'QgsComposerItem' object has no attribute 'columns'
table.type()
65651
table.multiFrame()
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'QgsComposerItem' object has no attribute 'multiFrame'

QGis 2.18 Windows

myComposition = iface.activeComposers()[1].composition()
table = myComposition.getComposerItemById('attr')
type(table)
<class 'qgis._core.QgsComposerFrame'>
table.type()
65651
table.multiFrame()
<qgis._core.QgsComposerAttributeTableV2 object at 0x00000000167CE268>

Did I missing something?

Thanks

History

#1 Updated by Nyall Dawson about 3 years ago

  • Resolution set to up/downstream
  • Status changed from Open to Closed

This is an upstream bug in newer version of the pyqt4/sip libraries which the python bindings are built using. Upstream is no longer actively developing the qt4 versions of the library, so we're stuck with this bug until 3.0

I tried many workarounds in the qgis code but we cannot fix this - it needs to be fixed upstream..

#2 Updated by Christophe Damour almost 3 years ago

This problem is still there with QGIS 2.99 :
myLayout.itemById('myid') returns qgsLayoutItem object instead of the object subclass (ie. QgsLayoutItemLabel).

Also available in: Atom PDF