<div class="gmail_quote"><br>Hi all,<br><br>I have made a py plugin that plot points at a given position over an underlying map.<br>At a given rate (1 time per second for example) the points change position and move over the map.<br>
I have used QgsVertexMarker to do this.<br>
<br>Now I am trying to plot instead of the "icon" make available by QgsVertexMarker class, a custom image loaded from a file.<br>SO I modified the class in the following way:<br><br><ul><li>add ICON_CUSTOM to the enum</li>
</ul><br>enum IconType<br> {<br> ICON_NONE,<br> ICON_CROSS,<br> ICON_X,<br> ICON_BOX,<br> ICON_CUSTOM<br> };<br><br><ul><li>add the method </li></ul>void QgsVertexMarker::setIconFileName (QString fname)<br>
{<br> mFileName=fname; <br><br>}<br><br><ul><li>modify the QgsVertexMarker::paint</li></ul>void QgsVertexMarker::paint( QPainter* p )<br>{<br> qreal s = ( mIconSize - 1 ) / 2;<br><br> QPen pen( mColor );<br> pen.setWidth( mPenWidth );<br>
p->setPen( pen );<br><br> switch ( mIconType )<br> {<br> case ICON_NONE:<br> break;<br><br> case ICON_CROSS:<br> p->drawLine( QLineF( -s, 0, s, 0 ) );<br> p->drawLine( QLineF( 0, -s, 0, s ) );<br>
break;<br><br> case ICON_X:<br> p->drawLine( QLineF( -s, -s, s, s ) );<br> p->drawLine( QLineF( -s, s, s, -s ) );<br> break;<br><br> case ICON_BOX:<br> p->drawLine( QLineF( -s, -s, s, -s ) );<br>
p->drawLine( QLineF( s, -s, s, s ) );<br> p->drawLine( QLineF( s, s, -s, s ) );<br> p->drawLine( QLineF( -s, s, -s, -s ) );<br> break;<br> case ICON_CUSTOM:<br> <br> QPixmap pixmap(QSize(22,22));<br>
pixmap.load(mFileName);<br> p->drawPixmap(0,0,pixmap);<br> break;<br> }<br>}<br><br><br><ul><li>update the binding file .sip</li></ul>The problem now is that the icon (png file) is not plotted correctly until I refresh the map canvas. <br>
See the attached images. <br>notcorrectvisualization.png is what I obtain on the screen<br>and<br>correctvisualization.png is waht I obtain after pushed the refresh button.<br><br>Any suggestion to solve ??<br><br></div>