0

I followed the QGIS 3 cookbook and created a new custom symbol layer class. But when I try to create a new the symbol, QGIS crashes. I create it like this.

symbol = QgsMarkerSymbol({FooMarker(20)})

The link for the cookbook is the following: https://docs.qgis.org/testing/pdf/en/QGIS-testing-PyQGISDeveloperCookbook-en.pdf page: 31

My FooMarker class looks like this.

class FooMarker(QgsMarkerSymbolLayer):
    def __init__(self, radius=4.0):
        QgsMarkerSymbolLayer.__init__(self)
        self.radius = radius
        self.color = QColor(255,0,0)

    def layerType(self):
        return "FooMarker"

    def properties(self):
        return {"radius": str(self.radius)}

    def startRender(self, context):
        pass

    def stopRender(self, context):
        pass

   def renderPoint(self, point, context):
        color = context.selectionColor() if context.selected() else self.color
        p = context.renderContext().painter()
        p.setPen(color)
        p.drawEllipse(point, self.radius, self.radius)

    def clone(self):
        return FooMarker(self.radius)
  • One problem is curly brackets. If QGIS keeps crashing after changing {} into [], that means you have different issue with code. As it's currently written (one line of code), it’s hard to tell exactly what problem is. Add extra explanation/code etc. to your question. You can add class FooMarker block, for example. Maybe the problem is within the class body. – Kadir Şahbaz Oct 3 '18 at 10:46
  • I have added my class to the question. – Blinxen Oct 3 '18 at 10:53
1

According to QGIS API Documentation QgsMarkerSymbol class needs QgsSymbolLayerList. That means a list in python.

QgsMarkerSymbol (const QgsSymbolLayerList & layers = QgsSymbolLayerList())

But you use {} and that means you pass a dictionary to QgsMarkerSymbol constructor method. If you change {FooMarker(20)} into [FooMarker(20)], QGIS doesn't crash.

  • Well that makes sense and I changed it but QGIS still crashes. – Blinxen Oct 3 '18 at 10:39
  • In QGIS 3.2.1, when I run symbol = QgsMarkerSymbol([FooMarker(20)]), QGIS doesn't crash. Are you sure you encounter crashing because of that line (symbol = ...) – Kadir Şahbaz Oct 3 '18 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.