When working with vector layers in QGIS, I can display the feature count of a layer and, if applicable, the feature count per attribute category (e.g. when using categorized or graduated styling) via the context menu of the layer. The counts are added to the layer title that is displayed in the layer widget.
How can I set activate this feature via the Python console/running a script? Looking through the API docs, I found a method to get the feature counts and further use them in your script. However, how can I display them as they would show when using the GUI?
It is probably possible somehow by retrieving the feature count as described above and then changing the layer widget symbology, adding the count to the title. However, this is rather cumbersome, so I wonder if there is a direct way to achieve this? If not, how would this best be done manually?