4

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)
1
  • 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. Oct 3, 2018 at 10:46

1 Answer 1

5

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

QgsMarkerSymbol (const QgsSymbolLayerList & layers = QgsSymbolLayerList())

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

2
  • 1
    Well that makes sense and I changed it but QGIS still crashes.
    – Blinxen
    Oct 3, 2018 at 10:39
  • 1
    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 = ...) Oct 3, 2018 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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