<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="js-vote-count grid--cell fc-black-500 fs-title grid
      fd-column ai-center" itemprop="upvoteCount" data-value="1">Some
      days ago I upgraded from QGIS 2.18 to 3.6.0 - not knowing that
      many Python scripts won't run without modifications.
    </div>
    <p>I could convert all of them but not this one:</p>
    <pre class="lang-py prettyprint prettyprinted" style=""><code><span class="kwd">from</span><span class="pln"> </span><span class="typ">PyQt4</span><span class="pun">.</span><span class="typ">QtCore</span><span class="pln"> </span><span class="kwd">import</span><span class="pln"> </span><span class="pun">*</span><span class="pln">
</span><span class="kwd">from</span><span class="pln"> </span><span class="typ">PyQt4</span><span class="pun">.</span><span class="typ">QtGui</span><span class="pln"> </span><span class="kwd">import</span><span class="pln"> </span><span class="pun">*</span><span class="pln">
</span><span class="kwd">from</span><span class="pln"> </span><span class="typ">PyQt4</span><span class="pln"> </span><span class="kwd">import</span><span class="pln"> </span><span class="typ">QtGui</span><span class="pln"> 
</span><span class="kwd">import</span><span class="pln"> processing</span><span class="pun">,</span><span class="pln"> sys</span><span class="pun">,</span><span class="pln"> time</span><span class="pun">,</span><span class="pln"> psycopg2
</span><span class="kwd">import</span><span class="pln"> pprint

</span><span class="pun">...</span><span class="pln">
creatin layers skipped </span><span class="pun">(</span><span class="pln">got this running</span><span class="pun">)</span><span class="pln">
</span><span class="pun">...</span><span class="pln">

</span><span class="com">################### Create Graph #####################</span><span class="pln">

mapRenderer </span><span class="pun">=</span><span class="pln"> iface</span><span class="pun">.</span><span class="pln">mapCanvas</span><span class="pun">().</span><span class="pln">mapRenderer</span><span class="pun">()</span><span class="pln">

layers </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="pln">missingLayer</span><span class="pun">.</span><span class="pln">id</span><span class="pun">(),</span><span class="pln">clipLayer</span><span class="pun">.</span><span class="pln">id</span><span class="pun">()]</span><span class="pln">
mapRenderer</span><span class="pun">.</span><span class="pln">setLayerSet</span><span class="pun">(</span><span class="pln">layers</span><span class="pun">)</span><span class="pln">

c </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsComposition</span><span class="pun">(</span><span class="pln">mapRenderer</span><span class="pun">)</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">setPlotStyle</span><span class="pun">(</span><span class="typ">QgsComposition</span><span class="pun">.</span><span class="typ">Print</span><span class="pun">)</span><span class="pln">

c</span><span class="pun">.</span><span class="pln">setPaperSize</span><span class="pun">(</span><span class="lit">148</span><span class="pun">,</span><span class="lit">90</span><span class="pun">)</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">setPrintResolution</span><span class="pun">(</span><span class="lit">300</span><span class="pun">)</span><span class="pln">

</span><span class="com"># add map</span><span class="pln">
x</span><span class="pun">,</span><span class="pln"> y </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pln">
w</span><span class="pun">,</span><span class="pln"> h </span><span class="pun">=</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">paperWidth</span><span class="pun">(),</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">paperHeight</span><span class="pun">()</span><span class="pln">
composerMap </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsComposerMap</span><span class="pun">(</span><span class="pln">c</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln">y</span><span class="pun">,</span><span class="pln">w</span><span class="pun">,</span><span class="pln">h</span><span class="pun">)</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">addItem</span><span class="pun">(</span><span class="pln">composerMap</span><span class="pun">)</span><span class="pln">

</span><span class="com">#output to image</span><span class="pln">
dpi </span><span class="pun">=</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">printResolution</span><span class="pun">()</span><span class="pln">
dpmm </span><span class="pun">=</span><span class="pln"> dpi </span><span class="pun">/</span><span class="pln"> </span><span class="lit">25.4</span><span class="pln">
width </span><span class="pun">=</span><span class="pln"> int</span><span class="pun">(</span><span class="pln">dpmm </span><span class="pun">*</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">paperWidth</span><span class="pun">())</span><span class="pln">
height </span><span class="pun">=</span><span class="pln"> int</span><span class="pun">(</span><span class="pln">dpmm </span><span class="pun">*</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">paperHeight</span><span class="pun">())</span><span class="pln">

</span><span class="typ">BackgroundColor</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QColor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">)</span><span class="pln">

</span><span class="com"># create output image and initialize it</span><span class="pln">
image </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QImage</span><span class="pun">(</span><span class="typ">QSize</span><span class="pun">(</span><span class="pln">width</span><span class="pun">,</span><span class="pln"> height</span><span class="pun">),</span><span class="pln"> </span><span class="typ">QImage</span><span class="pun">.</span><span class="typ">Format_ARGB32</span><span class="pun">)</span><span class="pln">
image</span><span class="pun">.</span><span class="pln">setDotsPerMeterX</span><span class="pun">(</span><span class="pln">dpmm </span><span class="pun">*</span><span class="pln"> </span><span class="lit">1000</span><span class="pun">)</span><span class="pln">
image</span><span class="pun">.</span><span class="pln">setDotsPerMeterY</span><span class="pun">(</span><span class="pln">dpmm </span><span class="pun">*</span><span class="pln"> </span><span class="lit">1000</span><span class="pun">)</span><span class="pln">
image</span><span class="pun">.</span><span class="pln">fill</span><span class="pun">(</span><span class="typ">BackgroundColor</span><span class="pun">)</span><span class="pln">

header </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsComposerLabel</span><span class="pun">(</span><span class="pln">c</span><span class="pun">)</span><span class="pln">
header</span><span class="pun">.</span><span class="pln">setItemPosition</span><span class="pun">(</span><span class="lit">40</span><span class="pun">,</span><span class="lit">1</span><span class="pun">)</span><span class="pln">
header</span><span class="pun">.</span><span class="pln">setBackgroundEnabled</span><span class="pun">(</span><span class="lit">0</span><span class="pun">)</span><span class="pln">
newFont </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QFont</span><span class="pun">(</span><span class="str">"Comic Sans MS"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">18</span><span class="pun">)</span><span class="pln">
header</span><span class="pun">.</span><span class="pln">setFont</span><span class="pun">(</span><span class="pln">newFont</span><span class="pun">)</span><span class="pln">
header</span><span class="pun">.</span><span class="pln">setText</span><span class="pun">(</span><span class="str">"Missing Countries Map"</span><span class="pun">)</span><span class="pln">
header</span><span class="pun">.</span><span class="pln">adjustSizeToText</span><span class="pun">()</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">addItem</span><span class="pun">(</span><span class="pln">header</span><span class="pun">)</span><span class="pln">

header2 </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsComposerLabel</span><span class="pun">(</span><span class="pln">c</span><span class="pun">)</span><span class="pln">
header2</span><span class="pun">.</span><span class="pln">setItemPosition</span><span class="pun">(</span><span class="lit">50</span><span class="pun">,</span><span class="lit">11</span><span class="pun">)</span><span class="pln">
header2</span><span class="pun">.</span><span class="pln">setBackgroundEnabled</span><span class="pun">(</span><span class="lit">0</span><span class="pun">)</span><span class="pln">
newFont2 </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QFont</span><span class="pun">(</span><span class="str">"Comic Sans MS"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">)</span><span class="pln">
header2</span><span class="pun">.</span><span class="pln">setFont</span><span class="pun">(</span><span class="pln">newFont2</span><span class="pun">)</span><span class="pln">
header2</span><span class="pun">.</span><span class="pln">setText</span><span class="pun">(</span><span class="str">"TS="</span><span class="pun">+</span><span class="pln">ts</span><span class="pun">)</span><span class="pln">
header2</span><span class="pun">.</span><span class="pln">adjustSizeToText</span><span class="pun">()</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">addItem</span><span class="pun">(</span><span class="pln">header2</span><span class="pun">)</span><span class="pln">

footer </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsComposerLabel</span><span class="pun">(</span><span class="pln">c</span><span class="pun">)</span><span class="pln">
footer</span><span class="pun">.</span><span class="pln">setItemPosition</span><span class="pun">(</span><span class="lit">124</span><span class="pun">,</span><span class="lit">87.5</span><span class="pun">)</span><span class="pln">
footer</span><span class="pun">.</span><span class="pln">setBackgroundEnabled</span><span class="pun">(</span><span class="lit">0</span><span class="pun">)</span><span class="pln">
newFont3 </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QFont</span><span class="pun">(</span><span class="str">"Times Roman"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">)</span><span class="pln">
footer</span><span class="pun">.</span><span class="pln">setFont</span><span class="pun">(</span><span class="pln">newFont3</span><span class="pun">)</span><span class="pln">
footer</span><span class="pun">.</span><span class="pln">setText</span><span class="pun">(</span><span class="pln">time</span><span class="pun">.</span><span class="pln">ctime</span><span class="pun">())</span><span class="pln">
footer</span><span class="pun">.</span><span class="pln">adjustSizeToText</span><span class="pun">()</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">addItem</span><span class="pun">(</span><span class="pln">footer</span><span class="pun">)</span><span class="pln">

legend </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsComposerLegend</span><span class="pun">(</span><span class="pln">c</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">model</span><span class="pun">().</span><span class="pln">setLayerSet</span><span class="pun">(</span><span class="pln">mapRenderer</span><span class="pun">.</span><span class="pln">layerSet</span><span class="pun">())</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setItemPosition</span><span class="pun">(</span><span class="lit">5</span><span class="pun">,</span><span class="lit">65</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setFrameEnabled</span><span class="pun">(</span><span class="lit">1</span><span class="pun">)</span><span class="pln">
newFont </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QFont</span><span class="pun">(</span><span class="str">"Comic Sans MS"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setStyleFont</span><span class="pun">(</span><span class="typ">QgsComposerLegendStyle</span><span class="pun">.</span><span class="typ">Title</span><span class="pun">,</span><span class="pln"> newFont</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setStyleFont</span><span class="pun">(</span><span class="typ">QgsComposerLegendStyle</span><span class="pun">.</span><span class="typ">Subgroup</span><span class="pun">,</span><span class="pln"> newFont</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setStyleFont</span><span class="pun">(</span><span class="typ">QgsComposerLegendStyle</span><span class="pun">.</span><span class="typ">SymbolLabel</span><span class="pun">,</span><span class="pln"> newFont</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setStyleMargin</span><span class="pun">(</span><span class="typ">QgsComposerLegendStyle</span><span class="pun">.</span><span class="typ">Title</span><span class="pun">,</span><span class="lit">2</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setTitle</span><span class="pun">(</span><span class="str">"Legend"</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setSymbolHeight</span><span class="pun">(</span><span class="lit">2</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">adjustBoxSize</span><span class="pun">()</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">addItem</span><span class="pun">(</span><span class="pln">legend</span><span class="pun">)</span><span class="pln">

</span><span class="com"># render the composition</span><span class="pln">
imagePainter </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QPainter</span><span class="pun">(</span><span class="pln">image</span><span class="pun">)</span><span class="pln">
imagePainter</span><span class="pun">.</span><span class="pln">setRenderHint</span><span class="pun">(</span><span class="typ">QPainter</span><span class="pun">.</span><span class="typ">Antialiasing</span><span class="pun">)</span><span class="pln">
sourceArea </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QRectF</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">paperWidth</span><span class="pun">(),</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">paperHeight</span><span class="pun">())</span><span class="pln">
targetArea </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QRectF</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">,</span><span class="pln"> height</span><span class="pun">)</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">render</span><span class="pun">(</span><span class="pln">imagePainter</span><span class="pun">,</span><span class="pln"> targetArea</span><span class="pun">,</span><span class="pln"> sourceArea</span><span class="pun">)</span><span class="pln">
imagePainter</span><span class="pun">.</span><span class="pln">end</span><span class="pun">()</span><span class="pln">
imageFile </span><span class="pun">=</span><span class="pln"> </span><span class="str">"missing_boundaries"</span><span class="pun">+</span><span class="pln">ts</span><span class="pun">+</span><span class="str">".png"</span><span class="pln">
</span><span class="kwd">print</span><span class="pln"> </span><span class="str">"saving to "</span><span class="pun">+</span><span class="pln">imageFile
image</span><span class="pun">.</span><span class="pln">save</span><span class="pun">(</span><span class="pln">imageFile</span><span class="pun">)

</span></code></pre>
    <p>Yes, I do know the QqsComposer has gone but I can't find any
      documentation or example for QGIS3 plotting. Except the API
      description of course.</p>
    <p>I don't need the whole script converted - <b>only a hint how to
        create a png the new way.</b></p>
    <p>regards</p>
    <p>walter<br>
      <b></b></p>
    <pre class="lang-py prettyprint prettyprinted" style="">
<code><span class="pun"></span></code></pre>
    <div class="moz-signature">-- <br>
      My projects:<br>
      <br>
      <a href="https://wambachers-osm.website/boundaries">Admin
        Boundaries of the World</a><br>
      <a
href="https://wambachers-osm.website/index.php/projekte/internationale-administrative-grenzen/missing-boundaries">Missing
        Boundaries</a><br>
      <a href="https://wambachers-osm.website/emergency">Emergency Map</a><br>
      <a href="https://wambachers-osm.website/plz">Postal Code Map
        (Germany only)</a><br>
      <a href="https://wambachers-osm.website/fools">Fools (QA for
        zipcodes in Germany)</a><br>
      <a href="https://wambachers-osm.website/pcoundaries"> Postcode
        Boundaries of Germany</a></div>
  </body>
</html>