<div dir="ltr">Hi Nyall,<div><br></div><div>Thanks very much for the advice. It is working now.</div><div><br></div><div>That was an excellent tip about checking the unit tests.</div><div dir="ltr"><div><br></div><div>James</div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, 1 Nov 2015 at 10:23 Nyall Dawson <<a href="mailto:nyall.dawson@gmail.com" target="_blank">nyall.dawson@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 1 November 2015 at 20:09, James Stott <<a href="mailto:jamesstott1@gmail.com" target="_blank">jamesstott1@gmail.com</a>> wrote:<br>
> I have an attribute table that is around two hundred rows of data (but only<br>
> two columns wide). I would like to add an attribute table to a composer with<br>
> this data, and to do this I need to add multiple frames so I can add the<br>
> whole attribute table to one page. Doing this manually in the composer I<br>
> just add 5 frames side by side to one composer page, and I manage to get all<br>
> my data on one page.<br>
><br>
> I cannot figure out how to add an attribute table with multiple frames to a<br>
> composer using PyQGIS. I am problably missing something really obvious, but<br>
> I am stuck here.<br>
><br>
> When I try to define a QgsComposerFrame, I am told that I must specify the<br>
> QgsComposerMultiFrame it belongs to:<br>
><br>
> QgsComposerFrame (QgsComposition *c, QgsComposerMultiFrame *mf, qreal x,<br>
> qreal y, qreal width, qreal height)<br>
><br>
> How do I create the QgsComposerMultiFrame. It is an abstract class, I am<br>
> told that it is an abstract class and cannot be instantiated. If I try<br>
><br>
> multiFrame = QgsComposerMultiFrame(myCompositionTable, False)<br>
><br>
> I get the following error when I run my code.<br>
><br>
> qgis._core.QgsComposerMultiFrame represents a C++ abstract class and cannot<br>
> be instantiated<br>
<br>
You create a QgsComposerAttributeTableV2 instead, which derives from<br>
QgsComposerMultiFrame. Here's some c++ code which does this, which<br>
should be pretty straightforward to translate to Python:<br>
<br>
<br>
mComposerAttributeTable = new QgsComposerAttributeTableV2(<br>
mComposition, false );<br>
mComposition->addMultiFrame( mComposerAttributeTable );<br>
<br>
mFrame1 = new QgsComposerFrame( mComposition, mComposerAttributeTable,<br>
5, 5, 100, 30 );<br>
mFrame2 = new QgsComposerFrame( mComposition, mComposerAttributeTable,<br>
5, 40, 100, 30 );<br>
<br>
mComposerAttributeTable->addFrame( mFrame1 );<br>
mComposerAttributeTable->addFrame( mFrame2 );<br>
<br>
mComposition->addComposerTableFrame( mComposerAttributeTable, mFrame1 );<br>
mComposition->addComposerTableFrame( mComposerAttributeTable, mFrame2 );<br>
<br>
mComposerAttributeTable->setVectorLayer( mVectorLayer );<br>
mComposerAttributeTable->setDisplayOnlyVisibleFeatures( false );<br>
mComposerAttributeTable->setMaximumNumberOfFeatures( 10 );<br>
mComposerAttributeTable->setContentFont( QgsFontUtils::getStandardTestFont() );<br>
mComposerAttributeTable->setHeaderFont( QgsFontUtils::getStandardTestFont() );<br>
mComposerAttributeTable->setBackgroundColor( Qt::yellow );<br>
<br>
When in doubt for something like this and you can't find any examples<br>
online, a good last resort to check is in the QGIS unit tests:<br>
<a href="https://github.com/qgis/QGIS/tree/master/tests/src" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/tree/master/tests/src</a><br>
(or in this case<br>
<a href="https://github.com/qgis/QGIS/blob/master/tests/src/core/testqgscomposertablev2.cpp" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/blob/master/tests/src/core/testqgscomposertablev2.cpp</a>)<br>
<br>
They are filled with minimal test cases such as this which are useful<br>
for seeing how various classes are intended to be used.<br>
<br>
Nyall<br>
<br>
<br>
<br>
<br>
><br>
> I cant find any documentation or examples on how to do this. So if someone<br>
> could shed some light on this it would be most appreciated. I am happy to<br>
> write up a bit of documentation once I have managed to do this.<br>
><br>
> Many thanks,<br>
><br>
> James<br>
><br>
> _______________________________________________<br>
> Qgis-developer mailing list<br>
> <a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div></div>