10

I am using QGIS 3.

I know that i can right click the layer and check the "show feature" option but is it possible to show enable this function by default when any layer is loaded ?

I know that we can set the project. I am looking for option to show it all time. a plugin for it will do.

1
  • as a note, including Show Feature Count for each layer in a project can result in extended load times as QGIS has to recount each layer when the project is open. Jun 16, 2020 at 16:33

1 Answer 1

14

You can use the following code in the Python Console, script or plugin which sets the featureCount setting to be enabled for any loaded vector layer:

def showFeatureCount(layers):
    layer = layers[0]
    if layer.type() == QgsMapLayer.VectorLayer:
        root = QgsProject.instance().layerTreeRoot()
        myLayerNode = root.findLayer(layer.id())
        myLayerNode.setCustomProperty("showFeatureCount", True)

QgsProject.instance().legendLayersAdded.connect(showFeatureCount)

If you want this to work from startup, you can use a startup script (or a plugin) and use the code shown above in addition to importing the following modules:

from qgis.core import QgsMapLayer, QgsProject
1
  • 1
    This should probably iterate over all the layers received from the signal, not just the first one. May 5, 2022 at 11:30

Your Answer

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

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