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
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.