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.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Abhijit Gujar
  • 2,750
  • 3
  • 29
  • 43
  • 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. – Hugh_Kelley Jun 16 '20 at 16:33

2 Answers2

15

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
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Joseph
  • 75,746
  • 7
  • 171
  • 282
5

For any future person reading this thread, there is now an option to show feature count by default when new layer is added.

Go to Settings -> Options -> Canvas & Legend -> tick the box next to Show feature count for newly added layers

Settings

Pawel
  • 408
  • 4
  • 15